1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionview/test/template
Sean Doyle 59ca21c011 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-11-30 18:47:49 -05:00
..
erb Allow Erubi bufvar to be configured 2020-05-21 15:22:51 -05:00
form_helper Yield translation to FormBuilder#button block 2020-10-30 16:30:56 -04:00
testing Support :any variants for FixtureResolver 2019-06-30 02:23:08 +09:00
active_model_helper_test.rb Raise deprecation for calling [:f] = 'b' or [:f] << 'b' 2019-03-31 22:59:12 +08:00
asset_tag_helper_test.rb set approriate crossorigin for js and css preload links 2020-10-21 18:26:41 -04:00
atom_feed_helper_test.rb Auto-correct rubocop offences 2019-11-24 09:54:47 +09:00
capture_helper_test.rb
compiled_templates_test.rb Remove actionview tests which modify fixtures 2019-06-05 18:40:06 -07:00
controller_helper_test.rb
csp_helper_test.rb Allow to pass options to csp_meta_tag 2019-02-16 09:36:37 +09:00
csrf_helper_test.rb form_authenticity_token takes keyword arguments 2019-09-15 03:05:52 +09:00
date_helper_i18n_test.rb This test needs integer core ext for time 2019-08-02 01:16:50 -04:00
date_helper_test.rb Add label attribute to <option> from include_blank 2020-07-24 15:45:18 -05:00
dependency_tracker_test.rb Ignore interpolated strings in DependencyTracker 2020-04-27 10:10:45 -07:00
digestor_test.rb Make Template::Resolver always cache 2019-03-15 09:20:05 -07:00
erb_util_test.rb
fallback_file_system_resolver_test.rb Deprecate rendering templates with . in the name 2020-05-05 23:21:17 -07:00
file_system_resolver_test.rb Add tests against resolver 2019-04-11 17:09:00 -07:00
form_collections_helper_test.rb
form_helper_test.rb Declare ActionView::Helpers::FormBuilder#id 2020-11-30 18:47:49 -05:00
form_options_helper_i18n_test.rb
form_options_helper_test.rb [v6.1.0.rc1] Fix regression for select tag helper with array (#40522) 2020-11-03 13:27:51 -05:00
form_tag_helper_test.rb Declare ActionView::Helpers::FormBuilder#id 2020-11-30 18:47:49 -05:00
html_test.rb Raise exception when building invalid mime type 2019-03-14 11:33:48 -07:00
javascript_helper_test.rb Fix possible XSS vector in JS escape helper 2020-03-19 09:48:08 -07:00
log_subscriber_test.rb Make the arguments of ActionView::Base#initialize required 2020-10-30 00:25:24 +00:00
lookup_context_test.rb Remove deprecated rendered_format from ActionView::LookupContext 2020-10-30 00:25:26 +00:00
number_helper_test.rb
optimized_file_system_resolver_test.rb Add tests against resolver 2019-04-11 17:09:00 -07:00
output_safety_helper_test.rb Suppress Ruby warning: ⚠️ non-nil $, will be deprecated 2019-07-29 12:55:28 +09:00
partial_iteration_test.rb fix require 2020-02-27 14:12:09 -08:00
record_identifier_test.rb
render_test.rb Require that ActionView::Base subclasses implement #compiled_method_container 2020-10-30 00:25:24 +00:00
resolver_cache_test.rb
resolver_shared_tests.rb Introduce Resolver::PathParser 2020-05-19 18:55:10 -07:00
sanitize_helper_test.rb
streaming_render_test.rb Remove deprecated support to passing relative paths to render file: 2020-10-30 00:25:14 +00:00
tag_helper_test.rb Escape HTML attributes for ERB interpolation (#40657) 2020-11-28 11:01:15 +01:00
template_error_test.rb Empty array instead of nil for source_extract 2019-07-14 15:04:25 -04:00
template_test.rb Remove deprecated ActionView::Template#refresh 2020-10-30 00:25:21 +00:00
test_case_test.rb Use unique controller per ActionView::TestCase 2020-09-02 15:55:01 -07:00
test_test.rb
text_helper_test.rb Passing in a Hash instance as kwargs parameters requires the "double splat" prefix 2019-09-05 13:26:58 +09:00
text_test.rb [ci skip] Renamed formats -> format in test after #35406 2019-02-26 08:35:15 +05:30
translation_helper_test.rb Improve Action View translate helper 2020-09-16 10:18:54 -05:00
url_helper_test.rb Merge pull request #25214 from maclover7/jm-av-tests 2019-12-18 12:23:11 -03:00