Custom form template
Create a custom form template
Create form template file
The new form field template class needs to extend to StratoxTemplate.
Break down
To make a quick breakdown of the above: the functions container
, input
and getAttr
are helper function, to make it easier for you create an input container that also holds a field label and input, creating the input tag fields or generate HTML attributes. They are not required, and you could just write your own HTML code and return that string, and it will work.
But to make it easier for you to understand let's take a look on how the textarea is build:
Helper functions:
Bellow is a list on helper functions that you can use in your form field template.
getAttr: It will merge specified attributes in the form builder with default attributes above, which we will then just add to the textarea. It is recommended that you use this function, with at least the name attribute, as shown in the example.
container: Will create input container that holds a label and description for your.
input: Will create input tag fields or generate HTML attributes.
isChecked: Will check if items like radio, checkboxes and select lists is active.
getFieldID: Will get a unique identifier that you can use as a element ID. E.G. the container function will automatically do this for you.
Accessible objects:
Bellow is a list on object that you can use in your form field template.
label: Will return the expected form field label
description: Will return a form field description you can use if you want
attr: Will return all expected form field attributes as object (recommended tho that you utilize getAttr function)
items: Will return the expected form field items (radio, checkboxes, and list in select lists).
name: Will return the expected form field attribute name
value: Will return the expected form field value
config: Will return the expected form field custom configs that is passable
Initialize the new template
You can now tell Stratox which form template file which is expected in the configuration.
Done you can now use your own form template!
Last updated