`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
8.8 KiB
-
ActionView::Helpers::FormBuilder#id
returns the value of the<form>
element'sid
attribute. With amethod
argument, returns theid
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
Rails 6.1.0.rc1 (November 02, 2020)
-
Yield translated strings to calls of
ActionView::FormBuilder#button
when a block is given.Sean Doyle
-
Alias
ActionView::Helpers::Tags::Label::LabelBuilder#translation
to#to_s
so thatform.label
calls can yield that value to their blocks.Sean Doyle
-
Rename the new
TagHelper#class_names
method toTagHelper#token_list
, and make the original available as an alias.token_list("foo", "foo bar") # => "foo bar"
Sean Doyle
-
ARIA Array and Hash attributes are treated as space separated
DOMTokenList
values. This is useful when declaring lists of label text identifiers inaria-labelledby
oraria-describedby
.tag.input type: 'checkbox', name: 'published', aria: { invalid: @post.errors[:published].any?, labelledby: ['published_context', 'published_label'], describedby: { published_errors: @post.errors[:published].any? } } #=> <input type="checkbox" name="published" aria-invalid="true" aria-labelledby="published_context published_label" aria-describedby="published_errors" >
Sean Doyle
-
Remove deprecated
escape_whitelist
fromActionView::Template::Handlers::ERB
.Rafael Mendonça França
-
Remove deprecated
find_all_anywhere
fromActionView::Resolver
.Rafael Mendonça França
-
Remove deprecated
formats
fromActionView::Template::HTML
.Rafael Mendonça França
-
Remove deprecated
formats
fromActionView::Template::RawFile
.Rafael Mendonça França
-
Remove deprecated
formats
fromActionView::Template::Text
.Rafael Mendonça França
-
Remove deprecated
find_file
fromActionView::PathSet
.Rafael Mendonça França
-
Remove deprecated
rendered_format
fromActionView::LookupContext
.Rafael Mendonça França
-
Remove deprecated
find_file
fromActionView::ViewPaths
.Rafael Mendonça França
-
Require that
ActionView::Base
subclasses implement#compiled_method_container
.Rafael Mendonça França
-
Remove deprecated support to pass an object that is not a
ActionView::LookupContext
as the first argument inActionView::Base#initialize
.Rafael Mendonça França
-
Remove deprecated
format
argumentActionView::Base#initialize
.Rafael Mendonça França
-
Remove deprecated
ActionView::Template#refresh
.Rafael Mendonça França
-
Remove deprecated
ActionView::Template#original_encoding
.Rafael Mendonça França
-
Remove deprecated
ActionView::Template#variants
.Rafael Mendonça França
-
Remove deprecated
ActionView::Template#formats
.Rafael Mendonça França
-
Remove deprecated
ActionView::Template#virtual_path=
.Rafael Mendonça França
-
Remove deprecated
ActionView::Template#updated_at
.Rafael Mendonça França
-
Remove deprecated
updated_at
argument required onActionView::Template#initialize
.Rafael Mendonça França
-
Make
locals
argument required onActionView::Template#initialize
.Rafael Mendonça França
-
Remove deprecated
ActionView::Template.finalize_compiled_template_methods
.Rafael Mendonça França
-
Remove deprecated
config.action_view.finalize_compiled_template_methods
Rafael Mendonça França
-
Remove deprecated support to calling
ActionView::ViewPaths#with_fallback
with a block.Rafael Mendonça França
-
Remove deprecated support to passing absolute paths to
render template:
.Rafael Mendonça França
-
Remove deprecated support to passing relative paths to
render file:
.Rafael Mendonça França
-
Remove support to template handlers that don't accept two arguments.
Rafael Mendonça França
-
Remove deprecated pattern argument in
ActionView::Template::PathResolver
.Rafael Mendonça França
-
Remove deprecated support to call private methods from object in some view helpers.
Rafael Mendonça França
-
ActionView::Helpers::TranslationHelper#translate
accepts a block, yielding the translated text and the fully resolved translation key:<%= translate(".relative_key") do |translation, resolved_key| %> <span title="<%= resolved_key %>"><%= translation %></span> <% end %>
Sean Doyle
-
Ensure cache fragment digests include all relevant template dependencies when fragments are contained in a block passed to the render helper. Remove the virtual_path keyword arguments found in CacheHelper as they no longer possess any function following
1581cab
.Fixes #38984.
Aaron Lipman
-
Deprecate
config.action_view.raise_on_missing_translations
in favor ofconfig.i18n.raise_on_missing_translations
.New generalized configuration option now determines whether an error should be raised for missing translations in controllers and views.
fatkodima
-
Instrument layout rendering in
TemplateRenderer#render_with_layout
asrender_layout.action_view
, and include (when necessary) the layout's virtual path in notification payloads for collection and partial renders.Zach Kemp
-
ActionView::Base.annotate_rendered_view_with_filenames
annotates HTML output with template file names.Joel Hawksley, Aaron Patterson
-
ActionView::Helpers::TranslationHelper#translate
returns nil when passeddefault: nil
without a translation matchingI18n#translate
.Stefan Wrobel
-
OptimizedFileSystemResolver
prefers template details in order of locale, formats, variants, handlers.Iago Pimenta
-
Added
class_names
helper to create a CSS class value with conditional classes.Joel Hawksley, Aaron Patterson
-
Add support for conditional values to TagBuilder.
Joel Hawksley
-
ActionView::Helpers::FormOptionsHelper#select
should mark option fornil
as selected.@post = Post.new @post.category = nil # Before select("post", "category", none: nil, programming: 1, economics: 2) # => # <select name="post[category]" id="post_category"> # <option value="">none</option> # <option value="1">programming</option> # <option value="2">economics</option> # </select> # After select("post", "category", none: nil, programming: 1, economics: 2) # => # <select name="post[category]" id="post_category"> # <option selected="selected" value="">none</option> # <option value="1">programming</option> # <option value="2">economics</option> # </select>
bogdanvlviv
-
Log lines for partial renders and started template renders are now emitted at the
DEBUG
level instead ofINFO
.Completed template renders are still logged at the
INFO
level.DHH
-
ActionView::Helpers::SanitizeHelper: support rails-html-sanitizer 1.1.0.
Juanito Fatas
-
Added
phone_to
helper method to create a link from mobile numbers.Pietro Moro
-
annotated_source_code returns an empty array so TemplateErrors without a template in the backtrace are surfaced properly by DebugExceptions.
Guilherme Mansur, Kasper Timm Hansen
-
Add autoload for SyntaxErrorInTemplate so syntax errors are correctly raised by DebugExceptions.
Guilherme Mansur, Gannon McGibbon
-
RenderingHelper
supports rendering objects thatrespond_to?
:render_in
.Joel Hawksley, Natasha Umer, Aaron Patterson, Shawn Allen, Emily Plummer, Diana Mounter, John Hawthorn, Nathan Herald, Zaid Zawaideh, Zach Ahn
-
Fix
select_tag
so that it doesn't changeoptions
wheninclude_blank
is present.Younes SERRAJ
Please check 6-0-stable for previous changes.