Class: IRuby::Input::Multiple
- Inherits:
-
Label
- Object
- Erector::Widget
- Widget
- Label
- IRuby::Input::Multiple
show all
- Defined in:
- lib/iruby/input/multiple.rb
Instance Method Summary
collapse
Methods inherited from Label
#widget_label
Methods inherited from Widget
builder, #content, #widget_display, #widget_join
Instance Method Details
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/iruby/input/multiple.rb', line 25
def widget_css
<<-CSS
.iruby-multiple {
display: table;
min-width: 25%;
}
.form-control.iruby-multiple-container {
display: table;
}
CSS
end
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/iruby/input/multiple.rb', line 56
def widget_html
widget_label do
div class: 'form-control iruby-multiple-container' do
params = {
size: @size,
multiple: true,
class: 'iruby-multiple',
:'data-iruby-key' => @key
}
select **params do
@options.each do |o|
option o, selected: @default.include?(o)
end
end
end
end
end
|
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/iruby/input/multiple.rb', line 37
def widget_js
<<-JS
$('.iruby-multiple').change(function(){
var multiple = $(this);
multiple.data('iruby-value', []);
multiple.find(':selected').each(function(){
multiple.data('iruby-value').push($(this).val());
});
if (multiple.data('iruby-value').length == 0) {
multiple.data('iruby-value', null);
}
});
$('.iruby-multiple').trigger('change');
JS
end
|