Skip to content

Commit 0e3678a

Browse files
authored
Merge pull request #16 from matestack/disabled_switch_and_select
Disabled switch and select
2 parents 1307650 + 8c490b6 commit 0e3678a

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed

lib/matestack/ui/bootstrap/form/checkbox.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ def response
1919

2020
private
2121

22+
def bootstrap_attributes
23+
classes = 'form-check-input'
24+
classes = [options[:class], classes].join(' ')
25+
{
26+
class: classes,
27+
disabled: context.disabled
28+
}
29+
end
30+
2231
def multiple?
2332
checkbox_options.present?
2433
end
@@ -28,15 +37,15 @@ def render_options
2837
if multiple?
2938
checkbox_options.to_a.each do |item|
3039
checkbox_wrapper do
31-
input options.merge(checkbox_attributes(item)).merge(class: 'form-check-input')
40+
input options.merge(checkbox_attributes(item)).merge(bootstrap_attributes)
3241
bootstrap_label text: item_label(item), for_input: item_id(item)
3342
end
3443
end
3544
# checked/unchecked checkbox (true/false checkbox)
3645
else
3746
checkbox_wrapper do
3847
input true_false_checkbox_attributes.merge(type: :hidden, id: nil, value: 0)
39-
input true_false_checkbox_attributes.merge(type: :checkbox, id: item_id(1), class: 'form-check-input')
48+
input true_false_checkbox_attributes.merge(type: :checkbox, id: item_id(1)).merge(bootstrap_attributes)
4049

4150
bootstrap_label text: input_label, for_input: item_id(1)
4251
end

lib/matestack/ui/bootstrap/form/radio.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ def response
2626

2727
end
2828

29+
private
2930

3031
def bootstrap_radio_attributes
32+
classes = 'form-check-input'
3133
{
32-
class: (options[:class] || "") << (" form-check-input"),
34+
class: (options[:class] || "") << classes,
3335
disabled: context.disabled
3436
}
3537
end

spec/test/form/checkbox_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@
203203
end
204204
end
205205
visit example_path
206-
have_xpath('//form//input[@id="foo_1" and @disabled="disabled" and contains(@class, "is-invalid")]')
207-
have_xpath('//form//input[@id="foo_2" and @disabled="disabled" and contains(@class, "is-invalid")]')
206+
expect(page).to have_xpath('//form//input[@id="foo_1" and @disabled="disabled"]')
207+
expect(page).to have_xpath('//form//input[@id="foo_2" and @disabled="disabled"]')
208208
end
209209

210210
it 'renders bootstrap checkbox button with label' do

spec/test/form/radio_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
expect(page).to have_selector('form > div.matestack-ui-bootstrap-radio > .form-check > label.form-check-label[for="foo_2"]')
3434

3535
find('#foo_1').click
36-
36+
3737
expect_any_instance_of(FormTestController).to receive(:expect_params)
3838
.with(hash_including(wrapper: { foo: 1 }))
3939

@@ -201,8 +201,8 @@
201201
end
202202
end
203203
visit example_path
204-
have_xpath('//form//input[@id="foo_1" and @disabled="disabled" and contains(@class, "is-invalid")]')
205-
have_xpath('//form//input[@id="foo_2" and @disabled="disabled" and contains(@class, "is-invalid")]')
204+
expect(page).to have_xpath('//form//input[@id="foo_1" and @disabled="disabled"]')
205+
expect(page).to have_xpath('//form//input[@id="foo_2" and @disabled="disabled"]')
206206
end
207207

208208
end

spec/test/form/switch_spec.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,19 @@
178178
end
179179

180180
it 'renders bootstrap switch button with additional custom class' do
181-
# add additional custom class to bootstrap switch
182-
183-
# form_config = get_form_config(path: switch_success_form_test_path)
184-
# matestack_render do
185-
# matestack_form form_config do
186-
# bs_form_switch key: :foo, options: [1, 2], class: "some-class"
187-
# bs_form_submit text: "Submit"
188-
# end
189-
# end
190-
# visit example_path
191-
# expect(page).to have_xpath('//form//switch[@id="foo" and contains(@class, "form-switch") and contains(@class, "some-class")]')
181+
182+
# add additional custom class to bootstrap switch
183+
form_config = get_form_config(path: switch_success_form_test_path)
184+
matestack_render do
185+
matestack_form form_config do
186+
bs_form_switch key: :foo, options: [1, 2], class: "some-class"
187+
bs_form_submit text: "Submit"
188+
end
189+
end
190+
visit example_path
191+
# expect(page).to have_xpath('//form//switch[@id="foo_1" and contains(@class, "form-switch") and contains(@class, "some-class")]')
192+
expect(page).to have_xpath('//form//input[@id="foo_1" and contains(@class, "some-class")]')
193+
expect(page).to have_xpath('//form//input[@id="foo_2" and contains(@class, "some-class")]')
192194
end
193195

194196
it 'renders disabled bootstrap switch buttons' do
@@ -200,8 +202,8 @@
200202
end
201203
end
202204
visit example_path
203-
have_xpath('//form//input[@id="_1" and @disabled="disabled" and contains(@class, "is-invalid")]')
204-
have_xpath('//form//input[@id="_2" and @disabled="disabled" and contains(@class, "is-invalid")]')
205+
expect(page).to have_xpath('//form//input[@id="foo_1" and @disabled="disabled"]')
206+
expect(page).to have_xpath('//form//input[@id="foo_2" and @disabled="disabled"]')
205207
end
206208

207209
it 'renders bootstrap switch button with label' do

0 commit comments

Comments
 (0)