Class: DatePicker::Styles::Flatpickr

Inherits:
Object
  • Object
show all
Defined in:
lib/date_picker/styles/flatpickr.rb

Instance Method Summary collapse

Instance Method Details

#mappingObject



7
8
9
# File 'lib/date_picker/styles/flatpickr.rb', line 7

def mapping
  :flatpickr
end

#templateObject



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
# File 'lib/date_picker/styles/flatpickr.rb', line 10

def template
  %{
    <input id="<%= input_id %>" name="<%= name %>"/>
    <script>
      (function() {
        var
          options = <%= picker_options %>,
          opts = {
            dateFormat: "<%= data_format %>",
            timeFormat: '\u2063',
            enableTime: <%= type.to_s != 'date' %>,
            noCalendar: <%= type.to_s == 'time' %>,
            utc: <%= type.to_s == 'time' %>,
            defaultDate: new Date(<%= time %>),
            minDate: <%= min ? 'new Date("' + min.to_s + '")' : 'undefined' %>,
            maxDate: <%= max ? 'new Date("' + max.to_s + '")' : 'undefined' %>,
            altInput: true,
            altFormat: "<%= picker_format %>",
            time_24hr: <%= /(?<!\\\\\\\\)H/ === picker_format %>
          }
        for (prop in opts) {
          options[prop] = opts[prop]
        }
        console.log("options: ", options);
        var
          picker = flatpickr && flatpickr('#<%= input_id %>', options);
        if (picker) {
          //picker.setDate(new Date(<%= time %>));
        }
      })();
    </script>
  }
end

#typesObject



4
5
6
# File 'lib/date_picker/styles/flatpickr.rb', line 4

def types
  [:date, :datetime, :time]
end