Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
155 views
in Technique[技术] by (71.8m points)

php - Add custom HTML attribute to buttons of a Grav generated form

I created a Bootstrap form with the following footer:

            <div class="modal-footer">
                <button type="button" 
                        class="btn btn-secondary" 
                        data-bs-dismiss="modal" // <----------------------
                  >Close
                </button>
                <button type="button" class="btn btn-primary">Send</button>
            </div>

In Grav, I created a form that is styled like my Bootstrap form. I used the official documentation. To close the modal and the form, I need to add the custom attribute data-bs-dismiss="modal" to the button which is generated by Grav:

    buttons:
        -
            type: reset
            value: Cancel
            classes: btn btn-secondary mx-3
            attributes: data-bs-dismiss="modal"   <-------- add custom attribute how?
        -
            type: submit
            value: 
            classes: btn btn-primary
    process: ...

My example code does not work.

How do I add a custom attribute in the form frontmatter so it is generated by Grav with the button?

There is no documentation what additional attributes or values are accepted by the Grav form plugin so I am at a loss. Just clicking anywhere on the screen is fine but I cannot expect all the not-as-tech-savy users to know this so I also need a button.

question from:https://stackoverflow.com/questions/66059072/add-custom-html-attribute-to-buttons-of-a-grav-generated-form

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You might give the following a try.

buttons:
  submit:
    type: submit
    value: Submit
    classes: btn btn-secondary
    attributes:
      data-bs-dismiss: modal

  reset:
    type: reset
    value: Reset

Generated element:

<button type="submit" data-bs-dismiss="modal" class="btn btn btn-secondary">Submit</button>

Note:

  • I haven't tested it using Bootstrap
  • Not sure if using 'attributes' has any side effects, but it seems to work.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...