2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/inputs/date_time_input.rb', line 2
def input(_wrapper_options)
raw_value = parse_value(object.public_send(attribute_name), options[:date_format])
disabled = options[:disabled] || false
hash = { id: "#{attribute_name}_datetimepicker", class: 'form-control datetimepicker-input', value: raw_value,
disabled: disabled, 'data-toggle': 'datetimepicker', 'data-target': "##{attribute_name}_datetimepicker", autocomplete: 'off' }
data = options[:data] || {}
data.keys.each do |d|
hash["data-#{d.to_s.dasherize}".to_sym] = data[d]
end
field = @builder.text_field(attribute_name, hash)
add_on_class = options[:add_on_class] || 'fa fa-calendar'
add_on = template.content_tag(:div, class: 'input-group-prepend') do
add_on = template.content_tag(:div, class: 'input-group-text') do
hash = { class: add_on_class, 'data-toggle': 'datetimepicker',
'data-target': "##{attribute_name}_datetimepicker" }
template.content_tag(:i, '', hash)
end
end
all = content_tag(:div, add_on + field, class: 'input-group')
script = ''.html_safe
unless disabled
picker_options = options[:picker_options] || { "format": 'MM/DD/YYYY' }
script = ''"
<script>
$(document).ready(function() {
$('##{attribute_name}_datetimepicker').datetimepicker(
#{picker_options.to_json}
);
});
</script>
"''.html_safe
end
all + script
end
|