mirror of
https://github.com/Bornholm/formidable.git
synced 2025-07-17 11:01:33 +02:00
feat: aggregate defaults and values
- Output merged defaults and values - Add "check" command
This commit is contained in:
@ -49,7 +49,7 @@ func (s *Server) handleFormReq(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
panic(errors.WithStack(err))
|
||||
} else {
|
||||
values, err = handleForm(r.Form, s.schema, values)
|
||||
values, err = handleForm(r.Form, s.schema, s.values)
|
||||
if err != nil {
|
||||
panic(errors.WithStack(err))
|
||||
}
|
||||
@ -57,7 +57,7 @@ func (s *Server) handleFormReq(w http.ResponseWriter, r *http.Request) {
|
||||
data.Values = values
|
||||
}
|
||||
|
||||
if err := s.schema.Validate(data.Values); err != nil {
|
||||
if err := s.schema.Validate(values); err != nil {
|
||||
validationErr, ok := err.(*jsonschema.ValidationError)
|
||||
if !ok {
|
||||
panic(errors.Wrap(err, "could not validate values"))
|
||||
@ -68,7 +68,7 @@ func (s *Server) handleFormReq(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if data.Error == nil {
|
||||
if s.onUpdate != nil {
|
||||
if err := s.onUpdate(data.Values); err != nil {
|
||||
if err := s.onUpdate(values); err != nil {
|
||||
panic(errors.Wrap(err, "could not update values"))
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{{ define "form_input_array" }}
|
||||
{{ $root := . }}
|
||||
{{ $fullProperty := getFullProperty .Parent .Property }}
|
||||
{{ $values := getValue .Defaults .Values $fullProperty }}
|
||||
{{ $values := getValue .Values $fullProperty }}
|
||||
<table width="100%">
|
||||
<tbody>
|
||||
{{ range $index, $value := $values }}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{{define "form_input_boolean"}}
|
||||
{{ $fullProperty := getFullProperty .Parent .Property }}
|
||||
{{ $checked := getValue .Defaults .Values $fullProperty }}
|
||||
{{ $checked := getValue .Values $fullProperty }}
|
||||
<label for="yes:{{ $fullProperty }}" class="inline-flex items-center mt-3">
|
||||
<input type="radio"
|
||||
class="h-5 w-5 text-gray-600"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{{define "form_input_number"}}
|
||||
{{ $fullProperty := getFullProperty .Parent .Property }}
|
||||
{{ $value := getValue .Defaults .Values $fullProperty }}
|
||||
{{ $value := getValue .Values $fullProperty }}
|
||||
<input type="number"
|
||||
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"
|
||||
name="num:{{ $fullProperty }}"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{{define "form_input_string"}}
|
||||
{{ $fullProperty := getFullProperty .Parent .Property }}
|
||||
{{ $value := getValue .Defaults .Values $fullProperty }}
|
||||
{{ $value := getValue .Values $fullProperty }}
|
||||
{{/* <input type="text"
|
||||
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"
|
||||
name="{{ $fullProperty }}"
|
||||
|
@ -162,11 +162,7 @@ func customHelpers(tpl *template.Template) template.FuncMap {
|
||||
|
||||
return fullProperty
|
||||
},
|
||||
"getValue": func(defaults, values interface{}, path string) (interface{}, error) {
|
||||
if defaults == nil {
|
||||
defaults = make(map[string]interface{})
|
||||
}
|
||||
|
||||
"getValue": func(values interface{}, path string) (interface{}, error) {
|
||||
if values == nil {
|
||||
values = make(map[string]interface{})
|
||||
}
|
||||
@ -178,13 +174,6 @@ func customHelpers(tpl *template.Template) template.FuncMap {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
if errors.Is(err, jsonpointer.ErrNotFound) {
|
||||
val, err = pointer.Get(defaults)
|
||||
if err != nil && !errors.Is(err, jsonpointer.ErrNotFound) {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
}
|
||||
|
||||
return val, nil
|
||||
},
|
||||
"getItemSchema": func(arraySchema *jsonschema.Schema) (*jsonschema.Schema, error) {
|
||||
|
Reference in New Issue
Block a user