Improve form and template usage (#66)

* Improve form and template usage.
This commit is contained in:
Mike Stefanello 2024-06-14 12:35:35 -04:00 committed by GitHub
parent 5f66b0ee71
commit 97bef0257e
22 changed files with 341 additions and 274 deletions

View file

@ -19,9 +19,9 @@
{{template "content" .}}
<div class="content is-small has-text-centered" hx-boost="true">
<a href="{{call .ToURL "login"}}">Login</a> &#9676;
<a href="{{call .ToURL "register"}}">Create an account</a> &#9676;
<a href="{{call .ToURL "forgot_password"}}">Forgot password?</a>
<a href="{{url "login"}}">Login</a> &#9676;
<a href="{{url "register"}}">Create an account</a> &#9676;
<a href="{{url "forgot_password"}}">Forgot password?</a>
</div>
</div>
</div>

View file

@ -9,7 +9,7 @@
<nav class="navbar is-dark">
<div class="container">
<div class="navbar-brand" hx-boost="true">
<a href="{{call .ToURL "home"}}" class="navbar-item">{{.AppName}}</a>
<a href="{{url "home"}}" class="navbar-item">{{.AppName}}</a>
</div>
<div id="navbarMenu" class="navbar-menu">
<div class="navbar-end">
@ -25,19 +25,19 @@
<aside class="menu" hx-boost="true">
<p class="menu-label">General</p>
<ul class="menu-list">
<li>{{link (call .ToURL "home") "Dashboard" .Path}}</li>
<li>{{link (call .ToURL "about") "About" .Path}}</li>
<li>{{link (call .ToURL "contact") "Contact" .Path}}</li>
<li>{{link (url "home") "Dashboard" .Path}}</li>
<li>{{link (url "about") "About" .Path}}</li>
<li>{{link (url "contact") "Contact" .Path}}</li>
</ul>
<p class="menu-label">Account</p>
<ul class="menu-list">
{{- if .IsAuth}}
<li>{{link (call .ToURL "logout") "Logout" .Path}}</li>
<li>{{link (url "logout") "Logout" .Path}}</li>
{{- else}}
<li>{{link (call .ToURL "login") "Login" .Path}}</li>
<li>{{link (call .ToURL "register") "Register" .Path}}</li>
<li>{{link (call .ToURL "forgot_password") "Forgot password" .Path}}</li>
<li>{{link (url "login") "Login" .Path}}</li>
<li>{{link (url "register") "Register" .Path}}</li>
<li>{{link (url "forgot_password") "Forgot password" .Path}}</li>
{{- end}}
</ul>
</aside>
@ -70,7 +70,7 @@
<h2 class="subtitle">Search</h2>
<p class="control">
<input
hx-get="{{call .ToURL "search"}}"
hx-get="{{url "search"}}"
hx-trigger="keyup changed delay:500ms"
hx-target="#results"
name="query"

View file

@ -12,7 +12,7 @@
{{end}}
{{define "form"}}
{{- if .Form.Submission.IsDone}}
{{- if .Form.IsDone}}
<article class="message is-large is-success">
<div class="message-header">
<p>Thank you!</p>
@ -22,13 +22,13 @@
</div>
</article>
{{- else}}
<form id="contact" method="post" hx-post="{{call .ToURL "contact.post"}}">
<form id="contact" method="post" hx-post="{{url "contact.post"}}">
<div class="field">
<label for="email" class="label">Email address</label>
<div class="control">
<input id="email" name="email" type="email" class="input {{.Form.Submission.GetFieldStatusClass "Email"}}" value="{{.Form.Email}}">
<input id="email" name="email" type="email" class="input {{.Form.GetFieldStatusClass "Email"}}" value="{{.Form.Email}}">
</div>
{{template "field-errors" (.Form.Submission.GetFieldErrors "Email")}}
{{template "field-errors" (.Form.GetFieldErrors "Email")}}
</div>
<div class="control">
@ -45,15 +45,15 @@
<input type="radio" name="department" value="hr" {{if eq .Form.Department "hr"}}checked{{end}}/>
HR
</label>
{{template "field-errors" (.Form.Submission.GetFieldErrors "Department")}}
{{template "field-errors" (.Form.GetFieldErrors "Department")}}
</div>
<div class="field">
<label for="message" class="label">Message</label>
<div class="control">
<textarea id="message" name="message" class="textarea {{.Form.Submission.GetFieldStatusClass "Message"}}">{{.Form.Message}}</textarea>
<textarea id="message" name="message" class="textarea {{.Form.GetFieldStatusClass "Message"}}">{{.Form.Message}}</textarea>
</div>
{{template "field-errors" (.Form.Submission.GetFieldErrors "Message")}}
{{template "field-errors" (.Form.GetFieldErrors "Message")}}
</div>
<div class="field is-grouped">

View file

@ -4,7 +4,7 @@
{{else if or (eq .StatusCode 403) (eq .StatusCode 401)}}
<p>You are not authorized to view the requested page.</p>
{{else if eq .StatusCode 404}}
<p>Click {{link (call .ToURL "home") "here" .Path}} to return home</p>
<p>Click {{link (url "home") "here" .Path}} to return home</p>
{{else}}
<p>Something went wrong</p>
{{end}}

View file

@ -1,5 +1,5 @@
{{define "content"}}
<form method="post" hx-boost="true" action="{{call .ToURL "forgot_password.post"}}">
<form method="post" hx-boost="true" action="{{url "forgot_password.post"}}">
<div class="content">
<p>Enter your email address and we'll email you a link that allows you to reset your password.</p>
</div>
@ -15,7 +15,7 @@
<button class="button is-primary">Reset password</button>
</p>
<p class="control">
<a href="{{call .ToURL "home"}}" class="button is-light">Cancel</a>
<a href="{{url "home"}}" class="button is-light">Cancel</a>
</p>
</div>
{{template "csrf" .}}

View file

@ -1,5 +1,5 @@
{{define "content"}}
<form method="post" hx-boost="true" action="{{call .ToURL "login.post"}}">
<form method="post" hx-boost="true" action="{{url "login.post"}}">
{{template "messages" .}}
<div class="field">
<label for="email" class="label">Email address</label>
@ -20,7 +20,7 @@
<button class="button is-primary">Log in</button>
</p>
<p class="control">
<a href="{{call .ToURL "home"}}" class="button is-light">Cancel</a>
<a href="{{url "home"}}" class="button is-light">Cancel</a>
</p>
</div>
{{template "csrf" .}}

View file

@ -1,31 +1,31 @@
{{define "content"}}
<form method="post" hx-boost="true" action="{{call .ToURL "register.post"}}">
<form method="post" hx-boost="true" action="{{url "register.post"}}">
<div class="field">
<label for="name" class="label">Name</label>
<div class="control">
<input type="text" id="name" name="name" class="input {{.Form.Submission.GetFieldStatusClass "Name"}}" value="{{.Form.Name}}">
{{template "field-errors" (.Form.Submission.GetFieldErrors "Name")}}
<input type="text" id="name" name="name" class="input {{.Form.GetFieldStatusClass "Name"}}" value="{{.Form.Name}}">
{{template "field-errors" (.Form.GetFieldErrors "Name")}}
</div>
</div>
<div class="field">
<label for="email" class="label">Email address</label>
<div class="control">
<input type="email" id="email" name="email" class="input {{.Form.Submission.GetFieldStatusClass "Email"}}" value="{{.Form.Email}}">
{{template "field-errors" (.Form.Submission.GetFieldErrors "Email")}}
<input type="email" id="email" name="email" class="input {{.Form.GetFieldStatusClass "Email"}}" value="{{.Form.Email}}">
{{template "field-errors" (.Form.GetFieldErrors "Email")}}
</div>
</div>
<div class="field">
<label for="password" class="label">Password</label>
<div class="control">
<input type="password" id="password" name="password" placeholder="*******" class="input {{.Form.Submission.GetFieldStatusClass "Password"}}">
{{template "field-errors" (.Form.Submission.GetFieldErrors "Password")}}
<input type="password" id="password" name="password" placeholder="*******" class="input {{.Form.GetFieldStatusClass "Password"}}">
{{template "field-errors" (.Form.GetFieldErrors "Password")}}
</div>
</div>
<div class="field">
<label for="password-confirm" class="label">Confirm password</label>
<div class="control">
<input type="password" id="password-confirm" name="password-confirm" placeholder="*******" class="input {{.Form.Submission.GetFieldStatusClass "ConfirmPassword"}}">
{{template "field-errors" (.Form.Submission.GetFieldErrors "ConfirmPassword")}}
<input type="password" id="password-confirm" name="password-confirm" placeholder="*******" class="input {{.Form.GetFieldStatusClass "ConfirmPassword"}}">
{{template "field-errors" (.Form.GetFieldErrors "ConfirmPassword")}}
</div>
</div>
<div class="field is-grouped">
@ -33,7 +33,7 @@
<button class="button is-primary">Register</button>
</p>
<p class="control">
<a href="{{call .ToURL "home"}}" class="button is-light">Cancel</a>
<a href="{{url "home"}}" class="button is-light">Cancel</a>
</p>
</div>
{{template "csrf" .}}

View file

@ -3,15 +3,15 @@
<div class="field">
<label for="password" class="label">Password</label>
<div class="control">
<input type="password" id="password" name="password" placeholder="*******" class="input {{.Form.Submission.GetFieldStatusClass "Password"}}">
{{template "field-errors" (.Form.Submission.GetFieldErrors "Password")}}
<input type="password" id="password" name="password" placeholder="*******" class="input {{.Form.GetFieldStatusClass "Password"}}">
{{template "field-errors" (.Form.GetFieldErrors "Password")}}
</div>
</div>
<div class="field">
<label for="password-confirm" class="label">Confirm password</label>
<div class="control">
<input type="password" id="password-confirm" name="password-confirm" placeholder="*******" class="input {{.Form.Submission.GetFieldStatusClass "ConfirmPassword"}}">
{{template "field-errors" (.Form.Submission.GetFieldErrors "ConfirmPassword")}}
<input type="password" id="password-confirm" name="password-confirm" placeholder="*******" class="input {{.Form.GetFieldStatusClass "ConfirmPassword"}}">
{{template "field-errors" (.Form.GetFieldErrors "ConfirmPassword")}}
</div>
</div>
<div class="field is-grouped">