feat: save latest summary in session storage to prevent loss of input
This commit is contained in:
@ -21,7 +21,28 @@ templ FormField(form *form.Form, id string, name string, label string) {
|
||||
}
|
||||
}
|
||||
|
||||
templ FormTextarea(form *form.Form, id string, name string, label string) {
|
||||
type FormTextareaOptions struct {
|
||||
Attrs map[string]any
|
||||
}
|
||||
|
||||
type FormTextareaOptionFunc func(opts *FormTextareaOptions)
|
||||
|
||||
func WithTextareaAttrs(kvAttrs ...any) FormTextareaOptionFunc {
|
||||
return func(opts *FormTextareaOptions) {
|
||||
opts.Attrs = keyValuesToAttrs(kvAttrs)
|
||||
}
|
||||
}
|
||||
|
||||
func newFormTextareaOptions(funcs ...FormTextareaOptionFunc) *FormTextareaOptions {
|
||||
opts := &FormTextareaOptions{}
|
||||
for _, fn := range funcs {
|
||||
fn(opts)
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
templ FormTextarea(form *form.Form, id string, name string, label string, funcs ...FormTextareaOptionFunc) {
|
||||
{{ opts := newFormTextareaOptions(funcs...) }}
|
||||
{{ field := form.Field(name) }}
|
||||
if field != nil {
|
||||
<div class="field">
|
||||
@ -29,7 +50,7 @@ templ FormTextarea(form *form.Form, id string, name string, label string) {
|
||||
<div class="control">
|
||||
{{ err, hasErr := form.Error(name) }}
|
||||
{{ value, hasValue := field.Get("value") }}
|
||||
<textarea class={ "textarea", templ.KV("is-danger", hasErr) } id={ id } name={ field.Name() } { field.Attrs()... }>
|
||||
<textarea class={ "textarea", templ.KV("is-danger", hasErr) } id={ id } name={ field.Name() } { mergeAttrs(field.Attrs(), opts.Attrs)... }>
|
||||
if hasValue {
|
||||
{ value.(string) }
|
||||
}
|
||||
|
Reference in New Issue
Block a user