Class: DrgcmsFormFields::HashField
- Inherits:
-
DrgcmsField
- Object
- DrgcmsField
- DrgcmsFormFields::HashField
- Defined in:
- app/models/drgcms_form_fields/hash_field.rb
Overview
Implementation of text_field DRG CMS form field.
Form options:
-
type:
text_field (required) -
name:
Field name (required) -
html:
html options which apply to text_field field (optional)
Form example:
10:
name: title
type: text_field
size: 30
html:
required: yes
Instance Attribute Summary
Attributes inherited from DrgcmsField
Class Method Summary collapse
-
.get_data(params, name) ⇒ Object
Return value.
Instance Method Summary collapse
-
#render ⇒ Object
Render text_field field html code.
-
#ro_standard ⇒ Object
Returns value for readonly field.
Methods inherited from DrgcmsField
#hash_to_options, #html, #initialize, #options_to_hash, #record_text_for, #set_css_code, #set_default_value, #set_initial_value, #set_style, #t
Constructor Details
This class inherits a constructor from DrgcmsFormFields::DrgcmsField
Class Method Details
.get_data(params, name) ⇒ Object
Return value. Return nil if input field is empty
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/models/drgcms_form_fields/hash_field.rb', line 75 def self.get_data(params, name) return nil if params['record'][name].blank? result = params['record'][name].split("\n").select { |e| !e.blank? } return if result.size == 0 # convert to Hash ret = {} result.map do |e| key, value = e.chomp.split(':') ret[key.strip] = value.strip if value.present? end ret end |
Instance Method Details
#render ⇒ Object
Render text_field field html code
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/drgcms_form_fields/hash_field.rb', line 59 def render return ro_standard if @readonly set_initial_value record = record_text_for(@yaml['name']) # Convert Hash to values separated by colon if @record[@yaml['name']] @yaml['html']['value'] = @record[@yaml['name']].to_a.inject('') {|r, e| r << "#{e.first}:#{e.last}\n"} end @html << @parent.text_area( record, @yaml['name'], @yaml['html']) self end |
#ro_standard ⇒ Object
Returns value for readonly field
46 47 48 49 50 51 52 53 54 |
# File 'app/models/drgcms_form_fields/hash_field.rb', line 46 def ro_standard() return self if @record[@yaml['name']].nil? html = '' @record[@yaml['name']].each do |key, value| html << "#{key}:#{value}<br>" end super(html) end |