text_field

When data input fields are grouped on single area they are defined by fields option.

 

  fields:
    10:
      name: name
      type: text_field 

 

All input fields are numbered, which has two advantages. It maintains order of fields on the form and can be easily removed or replaced with the program or by extending form.

 

name: defines name of the field defined in collection model. Name can also be a virtual field not defined in a model. Virtual fields can be used to trigger some actions but their value is not saved to database.

 

      25:
        name: _update_menu
        type: check_box
        help: helpers.help.dc_page._update_menu
        caption: helpers.label.dc_page._update_menu

 

In the example when check_box field is checked application will perform additional calculations (update pointer to page in menu) after document is saved.

 

name can also specify any method defined in model. In that case model must implements two methods to save and to get data from database.

 

      25:
        name: coord
        type: text_field

 

Class Spot
field: coordinates,  Array

def coord
  coordinates.join(',')
end

def coord=(value)
  self.coordinates = value.chomp.split(',')
end
end

 

In the example coordinates are saved as array in database but are entered as string separated with comma into input field.

 

Some other options which can apply to most of the fields.

 

      25:
        name: field_name
        type: text_field
        help: Help text
        label: Label
        readonly: true
        size: 20
        default: 60
or
        default:
          eval: "Time.now.beginning_of_year.strftime('%d.%m.%Y')"

 

help: defines text which is displayed when user hover over field label text. If help text contains dot then actual text must be defined in localization files.

 

label: or caption: Text display before (or on top) of the data entry field. If label text contains dot then actual text must be defined in localization files.

 

readonly: Field is displayed readonly. Readonly fields will be ignored when data is saved to database. When field is displayed as readonly and it must be saved to database use readonly or hidden type.

 

size: Size of the field on form which is translated to html size parameter for the field.

 

default: default value of the field can also be set on the form

 


Last update: 17.03.2021