grav-plugin-form
grav-plugin-form copied to clipboard
Q: field.attributes and button.attributes undocumented, but working
When using Bootstrap, it is sometimes necessary to add custom attributes to a field or button. For example to add a tooltip to a button:
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top" title="Tooltip on top">
Tooltip on top
</button>
After a bit of peeking at the form templates, I found that the following form definition works fine using an 'attributes' property for field definition and button definition:
form:
name: contact-form
fields:
name:
label: Name
type: text
attributes:
field-attr: field-attr-value
buttons:
submit:
type: submit
value: Submit
attributes:
button-attr: button-attr-value
Generated field:
<input name="data[name]" value="" type="text" class="form-input " field-attr="field-attr-value">
Generated button:
<button type="submit" button-attr="button-attr-value" class="btn ">Submit</button>
Questions:
- Is property 'attributes' supported?
- If so, shouldn't it be documented?
- If not, wouldn't it be a nice feature?
Support was added a couple of months ago: https://github.com/getgrav/grav-plugin-form/issues/448
We need to catch up on updates and PRs. We have had merged many PRs and fixed many issues and the docs have not been updated. Just a matter of resources.