Class: AgileFormFields::Readonly

Inherits:
AgileFormField show all
Defined in:
app/models/agile_form_fields/readonly.rb

Overview

Implementation of readonly AgileRails 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 agile_name_for_id helper

can be used to get value. Example: agile_name_for_id,model_name_in_lower_case,field_name

  • readonly: yes (can be applied to any field type)

Form example:

10:
  name: user
  type: readonly
  size: 50
20:
  name: created_by
  type: readonly
  eval: agile_name_for_id,ar_user,name

Instance Attribute Summary

Attributes inherited from AgileFormField

#css, #js

Instance Method Summary collapse

Methods inherited from AgileFormField

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 AgileFormFields::AgileFormField

Instance Method Details

#renderObject

Render readonly AgileRails form field code



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/agile_form_fields/readonly.rb', line 53

def render
  set_initial_value
  @record[@yaml['name']] = @yaml['html']['value'] if @yaml['html']['value']

  @html += @env.hidden_field('record', @yaml['name']) # retain field as hidden field
  @html += %(<div class="ar-readonly" id="record_#{@yaml['name']}_">)

  @html += if @yaml['eval']
             if @yaml['eval'].match(/agile_name_for_id/)
               parms = @env.agile_eval_to_array(@yaml['eval'])
               parms << nil if parms.size == 3
               @env.agile_name_for_id(parms[1], parms[2], parms[3], @record[@yaml['name']])
             else
               eval("#{@yaml['eval']}('#{@record.send(@yaml['name'])}')")
             end
           else
             @env.agile_format_value(@record.send(@yaml['name']), @yaml['format'])
           end
  @html += '</div>'
  self
end