Class: DrgcmsFormFields::Readonly
- Inherits:
-
DrgcmsField
- Object
- DrgcmsField
- DrgcmsFormFields::Readonly
- Defined in:
- app/models/drgcms_form_fields/readonly.rb
Overview
Implementation of readonly DRG CMS form field.
Readonly field value is just painted on form.
Form options:
-
name:
field name -
type:
readonly -
eval:
value will be provided by evaluating expression. Usually dc_name4_id helper
can be used to get value. Example: dc_name4_id,model_name_in_lower_case,field_name
-
readonly:
yes (can be applied to any field type)
Form example:
10:
name: user
type: readonly
html:
size: 50
20:
name: created_by
type: readonly
eval: dc_name4_id,dc_user,name
Instance Attribute Summary
Attributes inherited from DrgcmsField
Instance Method Summary collapse
-
#render ⇒ Object
Render readonly field html code.
Methods inherited from DrgcmsField
get_data, #hash_to_options, #html, #initialize, #options_to_hash, #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 readonly field html code
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/drgcms_form_fields/readonly.rb', line 54 def render set_initial_value @record[@yaml['name']] = @yaml['html']['value'] if @yaml['html']['value'] @html << @parent.hidden_field('record', @yaml['name']) # retain field as hidden field @html << %(<div class="dc-readonly" id="record_#{@yaml['name']}_">) @html << if @yaml['eval'] if @yaml['eval'].match(/dc_name4_id|dc_name_for_id/) parms = @parent.dc_eval_to_array(@yaml['eval']) parms << nil if parms.size == 3 @parent.dc_name_for_id(parms[1], parms[2], parms[3], @record[@yaml['name']]) else eval( "#{@yaml['eval']} '#{@record.send(@yaml['name'])}'") end else @parent.dc_format_value(@record.send(@yaml['name']), @yaml['format']) end @html << '</div>' self end |