Class: IRuby::Input::Checkbox
- Inherits:
-
Label
- Object
- Erector::Widget
- Widget
- Label
- IRuby::Input::Checkbox
show all
- Defined in:
- lib/iruby/input/checkbox.rb
Instance Method Summary
collapse
Methods inherited from Label
#widget_label
Methods inherited from Widget
builder, #content, #widget_display, #widget_join
Instance Method Details
15
16
17
|
# File 'lib/iruby/input/checkbox.rb', line 15
def widget_css
'.iruby-checkbox-container { margin-left: 10px; }'
end
|
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/iruby/input/checkbox.rb', line 36
def widget_html
params = {
:'data-iruby-key' => @key,
class: 'iruby-checkbox form-control'
}
widget_label do
div **params do
@options.each do |option|
label class: 'checkbox-inline' do
input(
name: @key, value: option, type: 'checkbox'
)
text option
end
end
end
end
end
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/iruby/input/checkbox.rb', line 19
def widget_js
<<-JS
$('.iruby-checkbox input').change(function(){
var parent = $(this).closest('.iruby-checkbox');
$(parent).data('iruby-value', []);
$(parent).find(':checked').each(function(){
$(parent).data('iruby-value').push($(this).val());
});
if ($(parent).data('iruby-value').length == 0) {
$(parent).data('iruby-value', null);
}
});
JS
end
|