Adds aria-invalid attribute to fields with errors
This commit is contained in:
parent
6f537ed98e
commit
644af1257a
|
@ -982,8 +982,8 @@ required attribute to force a value into an input and will prevent form submissi
|
||||||
Depending on the design of the application this may or may not be desired. In many cases it can
|
Depending on the design of the application this may or may not be desired. In many cases it can
|
||||||
break existing UI's.
|
break existing UI's.
|
||||||
|
|
||||||
It is possible to disable all HTML 5 extensions in **Simple Form** removing the `html5` component
|
It is possible to disable all HTML 5 extensions in **Simple Form** by removing the `html5`
|
||||||
from the wrapper used to render the inputs.
|
component from the wrapper used to render the inputs.
|
||||||
|
|
||||||
For example, change:
|
For example, change:
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ module SimpleForm
|
||||||
input_html_options[:required] = has_required?
|
input_html_options[:required] = has_required?
|
||||||
input_html_options[:'aria-required'] = has_required? || nil
|
input_html_options[:'aria-required'] = has_required? || nil
|
||||||
|
|
||||||
|
input_html_options[:'aria-invalid'] = has_errors?
|
||||||
|
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -94,13 +94,36 @@ class ErrorTest < ActionView::TestCase
|
||||||
assert_no_select 'span.error b', 'markup'
|
assert_no_select 'span.error b', 'markup'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test 'error generates an error message with raw HTML tags' do
|
test 'error generates an error message with raw HTML tags' do
|
||||||
with_error_for @user, :name, error_prefix: '<b>Name</b>'.html_safe
|
with_error_for @user, :name, error_prefix: '<b>Name</b>'.html_safe
|
||||||
assert_select 'span.error', "Name cannot be blank"
|
assert_select 'span.error', "Name cannot be blank"
|
||||||
assert_select 'span.error b', "Name"
|
assert_select 'span.error b', "Name"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'error adds aria-invalid attribute to inputs' do
|
||||||
|
with_form_for @user, :name, error: true
|
||||||
|
assert_select "input#user_name[name='user[name]'][aria-invalid='true']"
|
||||||
|
|
||||||
|
with_form_for @user, :name, as: :text, error: true
|
||||||
|
assert_select "textarea#user_name[name='user[name]'][aria-invalid='true']"
|
||||||
|
|
||||||
|
@user.errors.add(:active, 'must select one')
|
||||||
|
with_form_for @user, :active, as: :radio_buttons
|
||||||
|
assert_select "input#user_active_true[type=radio][name='user[active]'][aria-invalid='true']"
|
||||||
|
assert_select "input#user_active_false[type=radio][name='user[active]'][aria-invalid='true']"
|
||||||
|
|
||||||
|
with_form_for @user, :active, as: :check_boxes
|
||||||
|
assert_select "input#user_active_true[type=checkbox][aria-invalid='true']"
|
||||||
|
assert_select "input#user_active_false[type=checkbox][aria-invalid='true']"
|
||||||
|
|
||||||
|
with_form_for @user, :company_id, as: :select, error: true
|
||||||
|
assert_select "select#user_company_id[aria-invalid='true']"
|
||||||
|
|
||||||
|
@user.errors.add(:password, 'must not be blank')
|
||||||
|
with_form_for @user, :password
|
||||||
|
assert_select "input#user_password[type=password][aria-invalid='true']"
|
||||||
|
end
|
||||||
|
|
||||||
# FULL ERRORS
|
# FULL ERRORS
|
||||||
|
|
||||||
test 'full error generates a full error tag for the attribute' do
|
test 'full error generates a full error tag for the attribute' do
|
||||||
|
|
Loading…
Reference in New Issue