Class: AgileFormFields::CheckBox

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

Overview

Implementation of check_box AgileRails 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 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 check_box field html code



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

def render
  set_initial_value('html','default')
  # checked flag must be set
  @yaml['html']['checked'] = !@env.agile_dont?(@yaml['html']['default']) if @yaml['html']['default']
  # disabled if readonly
  @yaml['html']['disabled'] = true if @readonly
  # 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']
      @env.check_box(record, @yaml['name'], @yaml['html'], @yaml['checked_value'], @yaml['unchecked_value'] || '0')
    else
      @env.check_box(record, @yaml['name'], @yaml['html'])
    end
  @html += %(<label for="record_#{@yaml['name']}">#{@yaml['label']}</label>) if @yaml['label']
  self
end