Cleaned up conditional rendering.
This commit is contained in:
parent
02236266f1
commit
c8db468292
5 changed files with 71 additions and 56 deletions
|
|
@ -15,26 +15,27 @@ func ContactUs(ctx echo.Context, form *forms.Contact) error {
|
|||
r.Title = "Contact us"
|
||||
r.Metatags.Description = "Get in touch with us."
|
||||
|
||||
g := make(Group, 0)
|
||||
|
||||
if r.Htmx.Target != "contact" {
|
||||
g = append(g, components.Message(
|
||||
"is-link",
|
||||
"",
|
||||
Group{
|
||||
P(Text("This is an example of a form with inline, server-side validation and HTMX-powered AJAX submissions without writing a single line of JavaScript.")),
|
||||
P(Text("Only the form below will update async upon submission.")),
|
||||
}))
|
||||
}
|
||||
|
||||
if form.IsDone() {
|
||||
g = append(g, components.Message(
|
||||
"is-large is-success",
|
||||
"Thank you!",
|
||||
Text("No email was actually sent but this entire operation was handled server-side and degrades without JavaScript enabled."),
|
||||
))
|
||||
} else {
|
||||
g = append(g, form.Render(r))
|
||||
g := Group{
|
||||
Iff(r.Htmx.Target != "contact", func() Node {
|
||||
return components.Message(
|
||||
"is-link",
|
||||
"",
|
||||
Group{
|
||||
P(Text("This is an example of a form with inline, server-side validation and HTMX-powered AJAX submissions without writing a single line of JavaScript.")),
|
||||
P(Text("Only the form below will update async upon submission.")),
|
||||
},
|
||||
)
|
||||
}),
|
||||
Iff(form.IsDone(), func() Node {
|
||||
return components.Message(
|
||||
"is-large is-success",
|
||||
"Thank you!",
|
||||
Text("No email was actually sent but this entire operation was handled server-side and degrades without JavaScript enabled."),
|
||||
)
|
||||
}),
|
||||
Iff(!form.IsDone(), func() Node {
|
||||
return form.Render(r)
|
||||
}),
|
||||
}
|
||||
|
||||
return r.Render(layouts.Primary, g)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue