diff --git a/theme/bootstrap5.go b/theme/bootstrap5.go new file mode 100644 index 0000000..34d697e --- /dev/null +++ b/theme/bootstrap5.go @@ -0,0 +1,140 @@ +package theme + +var Bootstrap5 = map[string]string{ + "form": `
+ {{- form_error .Form nil -}} + + {{- form_help .Form -}} + + {{- range $field := .Form.Fields -}} + {{- form_row $field -}} + {{- end -}} +
`, + "attributes": `{{ range $key, $value := .Attributes }}{{ $key }}="{{ $value }}"{{ end }}`, + "help": ` + {{- if gt (len .Help) 0 -}} +
{{ .Help }}
+ {{- end -}} + `, + "label": ` + {{ if .Field.HasOption "label" }} + {{ $label := (.Field.GetOption "label").Value }} + + {{- if ne $label "" -}} + + {{- end -}} + {{- end -}} + `, + "input": ` + {{- $type := .Field.GetOption "type" -}} + {{- $checked := and (eq (.Field.GetOption "type").Value "checkbox") (.Field.Data) -}} + {{- $required := and (.Field.HasOption "required") (.Field.GetOption "required").Value -}} + {{- $value := .Field.Data -}} + {{- $class := "form-control" }} + + {{- if eq $type.Value "checkbox" -}} + {{- $value = 1 -}} + {{- end -}} + + {{- if or (eq $type.Value "checkbox") (eq $type.Value "radio") -}} + {{- $class = "form-check-input" -}} + {{- end -}} + + {{- if eq $type.Value "range" -}} + {{- $class = "form-range" -}} + {{- end -}} + + {{- if or (eq $type.Value "submit") (eq $type.Value "reset") (eq $type.Value "button") -}} + {{- $class = "" -}} + + {{ if .Field.HasOption "attr" }} + {{ $class = (.Field.GetOption "attr").Value.attr.class }} + {{ end }} + {{- end -}} + + + `, + "textarea": ` + + `, + "choice": ` + {{- $required := and (.Field.HasOption "required") (.Field.GetOption "required").Value -}} + {{- $isExpanded := (.Field.GetOption "expanded").Value -}} + {{- $isMultiple := (.Field.GetOption "multiple").Value -}} + {{- $emptyChoiceLabel := (.Field.GetOption "empty_choice_label").Value -}} + {{- $choices := (.Field.GetOption "choices").Value -}} + {{- $field := .Field -}} + {{- $keyAdd := 0 -}} + + {{- if and (not $required) (not $isMultiple) -}} + {{- $keyAdd = 1 -}} + {{- end -}} + + {{- if $isExpanded -}} + {{- if and (not $required) (not $isMultiple) -}} +
+ + +
+ {{- end -}} + + {{- range $key, $choice := $choices.GetChoices -}} +
+ + +
+ {{- end -}} + {{- else -}} + + {{- end -}} + `, + "sub_form": ` +
+ {{ if .Field.HasOption "label" }} + {{ $label := (.Field.GetOption "label").Value }} + + {{- if ne $label "" -}} + {{ $label }} + {{- end -}} + {{- end -}} + + {{ form_widget_help .Field }} + + {{- range $field := .Field.Children -}} + {{- form_row $field -}} + {{- end -}} +
+ `, + "error": ` + {{- if gt (len .Errors) 0 -}} +
+ {{- range $error := .Errors -}} +
{{- $error -}}
+ {{- end -}} +
+ {{- end -}} + `, + "row": `
+ {{ $labelAfterWidget := and (.Field.HasOption "type") (eq (.Field.GetOption "type").Value "checkbox") }} + + {{ if and (eq (len .Field.Children) 0) (not $labelAfterWidget) }} + {{- form_label .Field -}} + {{ end }} + + {{- form_widget .Field -}} + {{- form_error nil .Field -}} + + {{ if and (eq (len .Field.Children) 0) ($labelAfterWidget) }} + {{- form_label .Field -}} + {{ end }} + + {{- form_widget_help .Field -}} +
`, +}