Releases: justledbetter/form
Releases · justledbetter/form
Data type and handling options
I've added a handful of options that may be useful to formbuilders everywhere:
- value=xxxxx sets a static value for a form field that cannot be modified by user nor software input
- readonly=true prohibits users from changing settings (but displays dynamic content from the struct)
- header=true on sub-structs causes the form builder to insert a "header" block that can be rendered separate from form fields
When creating your input template, it's possible to use more advanced type= values to bring things into better focus. A more current example template looks like:
{{if eq .Type "hidden"}}
<input {{with .ID}}id="{{.}}"{{end}} type="{{.Type}}" name="{{.Name}}" value="{{.Value}}"/>
{{else if eq .Type "info"}}
<div>
<h2>{{.Label}}</h2>
<p>{{.Footer}}</p>
</div>
{{else if eq .Type "section"}}
<div>
<div>
{{if .Label}}{{.Label}}{{else}}{{.Name}}{{end}}
{{with .Footer}}
<p class="text-grey-400 pl-8 pt-2 text-xs italic">{{.}}</p>
{{end}}
</div>
</div>
{{else if eq .Type "checkbox"}}
<div>
<input type="checkbox" {{with .ID}}id="{{.}}"{{end}} name="{{.Name}}" placeholder="{{.Placeholder}}" {{with .Value}}checked{{end}}>
{{.Label}}
</input>
{{with .Footer}}
<i>{{.}}</i>
{{end}}
</div>
{{else}}
<div>
<label {{with .ID}}for="{{.}}"{{end}}>
{{.Label}}
</label>
<input {{with .ID}}id="{{.}}"{{end}} type="{{.Type}}" name="{{.Name}}" placeholder="{{.Placeholder}}" {{with .Value}}value="{{.}}"{{end}}/>
{{with .Footer}}
<p class="text-grey pt-2 text-xs italic">{{.}}</p>
{{end}}
</div>
{{end}}