1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionview/CHANGELOG.md

69 lines
2.4 KiB
Markdown
Raw Normal View History

Consistently render `button_to` as `<button>` Prior to this commit, the [ActionView::Helpers::UrlHelper#button_to][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`. [button_to]: https://api.rubyonrails.org/v6.0/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to Co-authored-by: Dusan Orlovic <duleorlovic@gmail.com>
2020-12-03 21:01:39 -05:00
* Change `ActionView::Helpers::UrlHelper#button_to` to *always* render a
`<button>` element, regardless of whether or not the content is passed as
the first argument or as a block.
Consistently render `button_to` as `<button>` Prior to this commit, the [ActionView::Helpers::UrlHelper#button_to][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`. [button_to]: https://api.rubyonrails.org/v6.0/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to Co-authored-by: Dusan Orlovic <duleorlovic@gmail.com>
2020-12-03 21:01:39 -05:00
<%= button_to "Delete", post_path(@post), method: :delete %>
<%# => <form method="/posts/1"><input type="_method" value="delete"><button type="submit">Delete</button></form>
<%= button_to post_path(@post), method: :delete do %>
Delete
<% end %>
<%# => <form method="/posts/1"><input type="_method" value="delete"><button type="submit">Delete</button></form>
*Sean Doyle*, *Dusan Orlovic*
Consistently render `button_to` as `<button>` Prior to this commit, the [ActionView::Helpers::UrlHelper#button_to][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`. [button_to]: https://api.rubyonrails.org/v6.0/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to Co-authored-by: Dusan Orlovic <duleorlovic@gmail.com>
2020-12-03 21:01:39 -05:00
* Add `config.action_view.preload_links_header` to allow disabling of
the `Link` header being added by default when using `stylesheet_link_tag`
and `javascript_include_tag`.
Consistently render `button_to` as `<button>` Prior to this commit, the [ActionView::Helpers::UrlHelper#button_to][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`. [button_to]: https://api.rubyonrails.org/v6.0/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to Co-authored-by: Dusan Orlovic <duleorlovic@gmail.com>
2020-12-03 21:01:39 -05:00
*Andrew White*
* The `translate` helper now resolves `default` values when a `nil` key is
specified, instead of always returning `nil`.
*Jonathan Hefner*
* Add `config.action_view.image_loading` to configure the default value of
the `image_tag` `:loading` option.
By setting `config.action_view.image_loading = "lazy"`, an application can opt in to
lazy loading images sitewide, without changing view code.
*Jonathan Hefner*
Declare ActionView::Helpers::FormBuilder#id `ActionView::Helpers::FormBuilder#id` --- Generate an HTML `id` attribute value. Return the [`<form>` element's][mdn-form] `id` attribute. ```html+erb <%= form_for @post do |f| %> <%# ... %> <% content_for :sticky_footer do %> <%= form.button(form: f.id) %> <% end %> <% end %> ``` In the example above, the `:sticky_footer` content area will exist outside of the `<form>` element. [By declaring the `form` HTML attribute][mdn-button-attr-form], we hint to the browser that the generated `<button>` element should be treated as the `<form>` element's submit button, regardless of where it exists in the DOM. [A similar pattern could be used for `<input>` elements][mdn-input-attr-form] (or other form controls) that do not descend from the `<form>` element. `ActionView::Helpers::FormBuilder#field_id` --- Generate an HTML <tt>id</tt> attribute value for the given field Return the value generated by the <tt>FormBuilder</tt> for the given attribute name. ```html+erb <%= form_for @post do |f| %> <%= f.label :title %> <%= f.text_field :title, aria: { describedby: form.field_id(:title, :error) } %> <span id="<%= f.field_id(:title, :error) %>">is blank</span> <% end %> ``` In the example above, the <tt><input type="text"></tt> element built by the call to <tt>FormBuilder#text_field</tt> declares an <tt>aria-describedby</tt> attribute referencing the <tt><span></tt> element, sharing a common <tt>id</tt> root (<tt>post_title</tt>, in this case). This method is powered by the `field_id` helper declared in `action_view/helpers/form_tag_helper`, which is made available for general template calls, separate from a `FormBuilder` instance. [mdn-form]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form [mdn-button-attr-form]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-form [mdn-input-attr-form]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-form [mdn-aria-describedby]: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute [w3c-wai]: https://www.w3.org/WAI/tutorials/forms/notifications/#listing-errors
2020-08-27 20:28:43 -04:00
* `ActionView::Helpers::FormBuilder#id` returns the value
of the `<form>` element's `id` attribute. With a `method` argument, returns
the `id` attribute for a form field with that name.
<%= form_for @post do |f| %>
<%# ... %>
<% content_for :sticky_footer do %>
<%= form.button(form: f.id) %>
<% end %>
<% end %>
*Sean Doyle*
* `ActionView::Helpers::FormBuilder#field_id` returns the value generated by
the FormBuilder for the given attribute name.
<%= form_for @post do |f| %>
<%= f.label :title %>
<%= f.text_field :title, aria: { describedby: f.field_id(:title, :error) } %>
<%= tag.span("is blank", id: f.field_id(:title, :error) %>
<% end %>
*Sean Doyle*
* Add `tag.attributes` to transform a Hash into HTML Attributes, ready to be
interpolated into ERB.
<input <%= tag.attributes(type: :text, aria: { label: "Search" }) %> >
# => <input type="text" aria-label="Search">
*Sean Doyle*
2020-12-02 18:37:26 -05:00
Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/actionview/CHANGELOG.md) for previous changes.