22

Github Consistently render `button_to` as `<button>` by seanpdoyle · Pull...

 4 years ago
source link: https://github.com/rails/rails/pull/40747
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Contributor

seanpdoyle commented on Dec 4, 2020

edited

Consistently render button_to as <button>

Prior to this commit, the
ActionView::Helpers::UrlHelper#button_to helper rendered
<input type="submit"> elements when passed its contents as a String
argument, and rendered <button type="submit"> elements when passed its
contents as a block.

This difference is subtle, and might lead to surprises.

Additionally, a <form> element's submitter can encode a name/value
pairing, which will be submitted as part of the request. When
button_to renders an <input type="submit"> element, the "button"
content is rendered as a [value] attribute, which prevents any
meaningful data from being encoded.

Since it's a single <button> or <input type="submit"> within a
<form>, missing out on that opportunity to encode information might
not be a show stopper, but ensuring that a <button> element is
rendered without a default [value] attribute enables applications to
encode additional information that can be accessed JavaScript as
element.value, instead of a workaround like
element.getAttribute("data-value").

Support rendering input elements with button_to

To support the original behavior of button_to rendering <input type="submit"> elements when invoked without a block, expose the
app.config.button_to_generates_button_tag configuration flag.

By default, it's set to true and ensures that all button_to calls
render <button> elements. To revert to the original behavior, set it
to false.

Co-authored-by: Dusan Orlovic [email protected]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK