Merge pull request #1460 from fschwahn/fix-falsey-unchecked-value
Exclude hidden field when unchecked_value: false
This commit is contained in:
commit
6039eed7c9
|
@ -60,7 +60,7 @@ module SimpleForm
|
||||||
# we need the hidden field to be *outside* the label (otherwise it
|
# we need the hidden field to be *outside* the label (otherwise it
|
||||||
# generates invalid html - html5 only).
|
# generates invalid html - html5 only).
|
||||||
def build_hidden_field_for_checkbox
|
def build_hidden_field_for_checkbox
|
||||||
return "" unless include_hidden?
|
return "" if !include_hidden? || !unchecked_value
|
||||||
options = { value: unchecked_value, id: nil, disabled: input_html_options[:disabled] }
|
options = { value: unchecked_value, id: nil, disabled: input_html_options[:disabled] }
|
||||||
options[:name] = input_html_options[:name] if input_html_options.has_key?(:name)
|
options[:name] = input_html_options[:name] if input_html_options.has_key?(:name)
|
||||||
|
|
||||||
|
|
|
@ -146,6 +146,14 @@ class BooleanInputTest < ActionView::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'input with nested style does not include hidden field when unchecked_value is false' do
|
||||||
|
swap SimpleForm, boolean_style: :nested do
|
||||||
|
with_input_for @user, :active, :boolean, unchecked_value: false
|
||||||
|
assert_select "label.boolean > input.boolean"
|
||||||
|
assert_no_select "input[type=hidden] + label.boolean"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test 'input boolean works using :input only in wrapper config (no label_input)' do
|
test 'input boolean works using :input only in wrapper config (no label_input)' do
|
||||||
swap_wrapper do
|
swap_wrapper do
|
||||||
with_input_for @user, :active, :boolean
|
with_input_for @user, :active, :boolean
|
||||||
|
|
Loading…
Reference in New Issue