Added enum field support in the ui.

This commit is contained in:
mikestefanello 2025-04-14 20:34:31 -04:00
parent aacb3d358f
commit 53113101c9
4 changed files with 58 additions and 12 deletions

View file

@ -19,16 +19,16 @@ type (
Help string
}
RadiosParams struct {
OptionsParams struct {
Form form.Form
FormField string
Name string
Label string
Value string
Options []Radio
Options []Choice
}
Radio struct {
Choice struct {
Value string
Label string
}
@ -88,7 +88,7 @@ func TextareaField(el TextareaFieldParams) Node {
)
}
func Radios(el RadiosParams) Node {
func Radios(el OptionsParams) Node {
buttons := make(Group, len(el.Options))
for i, opt := range el.Options {
buttons[i] = Label(
@ -114,6 +114,30 @@ func Radios(el RadiosParams) Node {
)
}
func SelectList(el OptionsParams) Node {
buttons := make(Group, len(el.Options))
for i, opt := range el.Options {
buttons[i] = Option(
Text(opt.Label),
Value(opt.Value),
If(opt.Value == el.Value, Attr("selected")),
)
}
return Div(
Class("control field"),
Label(Class("label"), Text(el.Label)),
Div(
Class("select"),
Select(
Name(el.Name),
buttons,
),
),
formFieldErrors(el.Form, el.FormField),
)
}
func Checkbox(el CheckboxParams) Node {
return Div(
Class("field"),