Class: DrgcmsFormFields::DateSelect
- Inherits:
-
DrgcmsField
- Object
- DrgcmsField
- DrgcmsFormFields::DateSelect
- Defined in:
- app/models/drgcms_form_fields.rb
Overview
Implementation of date_select DRG CMS form field.
Form options:
-
type:date_select (required) -
name:Field name (required) -
options:options which apply to date_select field (optional) -
html:html options which apply to password field (optional)
Form example:
50:
name: valid_from
type: date_select
options:
include_blank: true
html:
class: my-date-class
Instance Attribute Summary
Attributes inherited from DrgcmsField
Class Method Summary collapse
-
.get_data(params, name) ⇒ Object
Get data for DateSelect field According to gist.github.com/315227.
Instance Method Summary collapse
-
#render ⇒ Object
Render date_select field html code.
Methods inherited from DrgcmsField
#hash_to_options, #initialize, #record_text_for, #ro_standard, #set_initial_value, #t
Constructor Details
This class inherits a constructor from DrgcmsFormFields::DrgcmsField
Class Method Details
.get_data(params, name) ⇒ Object
Get data for DateSelect field According to gist.github.com/315227
858 859 860 861 862 863 864 865 866 867 868 869 870 |
# File 'app/models/drgcms_form_fields.rb', line 858 def self.get_data(params, name) attrs = params['record'].collect do |key, value| if key =~ /^#{Regexp.escape(name.to_s)}\((\d+)(\w)\)$/ [$1.to_i, value.send("to_#$2")] end end.compact.sort_by(&:first).map(&:last) # Return nil if error begin Time.zone.local(*attrs) #unless attrs.empty? rescue nil end end |
Instance Method Details
#render ⇒ Object
Render date_select field html code
842 843 844 845 846 847 848 849 850 851 852 |
# File 'app/models/drgcms_form_fields.rb', line 842 def render return ro_standard( @parent.dc_format_value(@record[@yaml['name']])) if @readonly # @yaml['options'] ||= {} set_initial_value('options','default') @yaml['options'].symbolize_keys! @yaml['html'].symbolize_keys! record = record_text_for(@yaml['name']) @html << @parent.date_select(record, @yaml['name'], @yaml['options'], @yaml['html']) self end |