grav-plugin-form icon indicating copy to clipboard operation
grav-plugin-form copied to clipboard

Q: field.attributes and button.attributes undocumented, but working

Open pamtbaau opened this issue 5 years ago • 2 comments

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?

pamtbaau avatar Feb 11 '21 07:02 pamtbaau

Support was added a couple of months ago: https://github.com/getgrav/grav-plugin-form/issues/448

mahagr avatar Feb 11 '21 10:02 mahagr

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.

rhukster avatar Feb 16 '21 21:02 rhukster