mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
Allow direct setting of for attribute on label, only overide with :input_html => :id if :input_html also contains a key :id
This commit is contained in:
parent
2f1b079c6e
commit
a484b560d1
2 changed files with 11 additions and 1 deletions
|
@ -37,7 +37,7 @@ module SimpleForm
|
|||
|
||||
def label_html_options
|
||||
label_options = html_options_for(:label, [input_type, required_class])
|
||||
label_options[:for] = options[:input_html][:id] if options.key?(:input_html)
|
||||
label_options[:for] = options[:input_html][:id] if options.key?(:input_html) && options[:input_html].key?(:id)
|
||||
label_options
|
||||
end
|
||||
|
||||
|
|
|
@ -170,6 +170,16 @@ class LabelTest < ActionView::TestCase
|
|||
assert_select 'label[for=my_new_id]'
|
||||
end
|
||||
|
||||
test 'label should allow overwriting of for attribute' do
|
||||
with_label_for @user, :name, :string, :label_html => { :for => 'my_new_id' }
|
||||
assert_select 'label[for=my_new_id]'
|
||||
end
|
||||
|
||||
test 'label should allow overwriting of for attribute with input_html not containing id' do
|
||||
with_label_for @user, :name, :string, :label_html => { :for => 'my_new_id' }, :input_html => {:class => 'foo'}
|
||||
assert_select 'label[for=my_new_id]'
|
||||
end
|
||||
|
||||
test 'label should use default input id when it was not overridden' do
|
||||
with_label_for @user, :name, :string, :input_html => { :class => 'my_new_id' }
|
||||
assert_select 'label[for=user_name]'
|
||||
|
|
Loading…
Reference in a new issue