head
Head keyword will create top level area on input form, which displays value of data field or method defined in a model. Main purpose of head area is to show common data (like names, dates, pictures), when data input form id divided into more than one tab. This way fields, which are usually hidden from view on first tab, can be seen, when other tabs are selected.
Split option defines into how many columns head area will be split. In example below, head area will be split into four columns.
split: 4
Name keyword defines name of method in the model which will be used to provide data to be displayed.
This can be name of the field defined in model or public method defined in model. But it can also define any method in any class or module as showed in third example.
10:
name: name
20:
name: name_and_surname
span: 2
30:
name: dummy_name
eval: MyModel.my_method
params: record
Simple model for above example.
field :name, String
field :surname, String
method name_and_surname()
"#{name} #{surname}"
end
method self.my_method(doc)
whatever_needs_to_be_calculated
end
end
Span keyword defines that field will span to 2 columns.
Params keyword defines that whole record will be passed to called method. Eval and params options are consistent with similar actions options.
Head fields can be styled with style, class and css option.
10:
name: name
style: "color: red"
20:
name: image
class: image-1
css: ".dc-column.image-1 img {position: absolute; right: 0px; top: 0; height: 6rem;}"
30:
name: state
style:
method: my_colors_control.color_for_state
In first example style is applied directly to html code of field name.
Second example shows how css code can be added directly to generated code. This usage is not recommended, but it serves the purpose. In our case class imge-1 is used , to avoid clashing with other images on other forms.
Third example shows how styles can be applied dynamically. In our case color changes depending of value of the state field.
method color_for_state(doc)
colors = %w(nil black blue green red)
"color: #{colors[doc.state]};" # state has value 1,2,3 or 4
end
end