Notes form

In next step we will create DRG form for browsing and editing notes. DRG CMS provides generator to generate initial form code. Go to application root directory and enter command:

 

rails generate new_drg_form note

 

This will create note.yml DRG form file in forms directory. Form file still needs some update but generator is usually a good start. The other option would be to edit an existing form and save it as note.yml.

 

After some polish our form looks like this.

table: note

index:
  filter: title, search as text_field
  actions:
    1:
      type: new
      caption: New note
    2: filter

result_set:
  filter: notes_filter
  actions:
    1: edit

  columns:
    10:
      name: title
      style: "text-align: left;"
    20:
      name: time_started
      style: "text-align: left;width: 80px;"
      format: '%d.%m.%Y'
    30:
      name: duration

form:
  fields:
    10:
      name: user_id
      type: readonly
      eval: dc_name4_id,dc_user,name
    20:
      name: title
      type: text_field
      size: 50
    30:
      name: time_started
      type: datetime_picker
      options:
        step: 15
    40:
      name: duration
      type: select
    50:
      name: body
      type: html_field
      options: "height: 500"

 

Our form is about note table (collection).

 

It will have two actions. New note and filter. Filter action will provide filtering only on title and search fields.

 

Result set must show only documents which belong to currently logged in user. This will be achieved by DrgcmsControls::NoteControl module notes_filter method which will be explained in next (DrgcmsControls) chapter.

 

Result set will display title, time_start and duration fields and will have only edit action.

 

Now to the form edit fields.

user_id is readonly field and it will be initialized in DrgcmsControls::NoteControl module. To display descriptive name instead of id we will use dc_name4_id helper. Parameters for dc_name4_id are collection (dc_user) and name of the field which will be used for display descriptive value from found document (name).

title is normal input (text_field). We also provide html parameter, to define fields length.

time_started is datetime_picker field. It's time picker part will have 15 minutes steps.

duration is select field. Choices for the field will be provided from choices4_duration localized label defined in previous chapter.

body can hold any text. So we will make it html_field. It's height will be 500 px.

 


Last update: 22.09.2021