Class: DrgcmsFormFields::CheckBox
- Inherits:
-
DrgcmsField
- Object
- DrgcmsField
- DrgcmsFormFields::CheckBox
- Defined in:
- app/models/drgcms_form_fields/check_box.rb
Overview
Implementation of check_box DRG CMS form field.
Form options:
-
name:
field name (required) -
type:
check_box (required) -
choices:
Values check_box separated by comma (1,0) (yes,no) -
checked_value:
1 or yes or approved -
label:
displayed right to square field -
unchecked_value:
0 or no or not approved -
html:
html options which apply to check_box field (optional)
Form example:
30:
name: active
type: check_box
40:
name: status
type: check_box
choices: yes,no
label: label
Instance Attribute Summary
Attributes inherited from DrgcmsField
Instance Method Summary collapse
-
#render ⇒ Object
Render check_box field html code.
Methods inherited from DrgcmsField
#__css_code, get_data, #hash_to_options, #html, #initialize, #record_text_for, #ro_standard, #set_css_code, #set_default_value, #set_initial_value, #set_style, #t
Constructor Details
This class inherits a constructor from DrgcmsFormFields::DrgcmsField
Instance Method Details
#render ⇒ Object
Render check_box field html code
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/drgcms_form_fields/check_box.rb', line 52 def render set_initial_value('html','default') # checked flag must be set @yaml['html']['checked'] = !@parent.dc_dont?(@yaml['html']['default']) if @yaml['html']['default'] # disable it if readonly @yaml['html']['disabled'] = @readonly ? true : nil # If choices are present split them to set checked and unchecked value @yaml['checked_value'], @yaml['unchecked_value'] = @yaml['choices'].split(',') if @yaml['choices'] @yaml['html'].symbolize_keys! record = record_text_for(@yaml['name']) @html << if @yaml['checked_value'] @parent.check_box(record, @yaml['name'], @yaml['html'], @yaml['checked_value'], @yaml['unchecked_value'] || '0') else @parent.check_box(record, @yaml['name'], @yaml['html']) end @html << "<label for=\"record_#{@yaml['name']}\">#{@yaml['label']}</label>" if @yaml['label'] self end |