Forms

Forms are an essential part of DRG CMS. One of the ideas for DRG CMS is to reduce the number of source files, which mostly contain boring repeating logic required for data editing. DRG CMS has only one controller which is used for data editing. CmseditController. Less source code also means less execution code and of course less code to debug errors. 

 

DRG Form is always loaded into iframe. Even more. Every embedded document defined by embedded field type is loaded into its own iframe. That is why editor must take care when saving data. In top level ''Save'' action saves only changes to top level fields. Changes in embedded documents will not be detected and therefore will not be saved. This is also valid for embedded document. When changing data in embedded document, only the nearest "Save" action (belonging to embedded form) will save data (only) to the embedded document. This complication in return provides huge simplification of editing data. 

 

Although Rails uses 4 basic actions on documents (index, new, edit, show)  basically there are only two situations when editing data. First is browsing table (collection). Second is editing record (document). Technically, editing an existing record or new empty record is the same. Showing data is also same as choosing editing data and just return without saving. So we have only two situations which need to be controlled. This is what the purpose of forms is. To direct CmseditController what document fields to display and what actions to perform on document data.

 

Forms are text files written in YAML format. Why YAML? Because YAML is the simplest format to write configuration files. Just like Ruby is the simplest language to write complex websites. There should be no arguing about this.

 

Form files can be located anywhere in the Rails project directory. Preferred location is app/forms directory, and application must be instructed where to look for form files. You do this by specifying this line in application.rb configuration file.

 

DrgCms.add_forms_path Rails.root.join('app/forms') # or your own path

 

This also applies when you create your own gem files as plugins. You must add this line to the gem initialization file.

 

DrgCms.add_forms_path File.expand_path("../../app/forms", __FILE__)

 

This will instruct DRG CMS where to look for additional form files.

 

A simple DRG form file looks like this:

 

## dc_books form
---
table: dc_book

index:
  filter: title
  actions: standard

result_set:
  actions:
    1: edit
    3: delete

  columns:
    10:  
      name: title
      width: 30%
    20:  
      name: author
    30:  
      name: active
      eval: dc_icon4_boolean

form:
  title:
    field: title
  actions: standard

  fields:
    10:
      name: title
      type: text_field
      size: 60
    20:
      name: description
      type: text_area
      size: 80x10
    30:
      name: author
      type: text_field
      size: 30

 

It has 3 major sections: index, result_set and form.

- index defines actions which can be executed when displaying result set. Actions are displayed on the top of result set as buttons with links.

- result_set defines fields which make up the data grid (browser), together with actions which are displayed in the first column of the record (document). They are used for executing operations on the selected document.

- form section also has its actions part followed by fields definition.

 

There are other form options like table, title, extend .... Let's look at these options in the following chapter.


Last update: 26.01.2022