Skip to content

Radio Button

Benjamin Mwalimu edited this page Jul 9, 2020 · 6 revisions

Radio Buttons Field

This is a radio button view used for selecting a single item among a list of options. It is identified by type native_radio in the JSON.

Field attributes

Field Attribute Usage Required
key Unique of the field yes
type Type of the field yes
label The radio button label no
label_text_style Defines the text style the radio button label will have. Accepts the following values bold, normal, italic, bold_italic no
text_color Specifies the color the radio button label will display. Accepts RGB color codes e.g #000000 no
extra_rel Denotes whether the radio button has an option that requires extra relevance. The values are either true/false. This is mostly used when an option opens up a subform or a date picker no
has_extra_rel Specifies the key of the radio button options that require extra relevance. Yes - if extra_rel = true otherwise no
options Holds the JSON array of the answers to be selected by the user yes
value Holds the user entry. It's a string literal, which is the key of the selected option. Only needed in case the field has a predefined entry otherwise it's always auto-generated/automatically added through code no
read_only Holds the read-only status of a specific field. true - means the user cannot enter/type anything on the field. They can only view what is presented no
v_required Status to indicate whether this field is required or not no
relevance Holds the rules to show/hide the specific field. This can use rules engine/ the line relevance (show in the example below) no
calculations Holds the link to the rules files that has a calculation affects the field in question no
openmrs_entity_parent Holds the concept id of the parent concept in OpenMRS no
openmrs_entity Holds the entity type on OpenMRS e.g Person, Address, Concept no
openmrs_entity_id Holds the concept id from OpenMRS no

Field Options attributes

Field Attribute Usage Required
key Unique of the field yes
text The option label yes
specify_info The text displayed in case the option has to open up date picker/ subform Yes - if extra_rel = true otherwise no
specify_info_color Specifies the specify_info text color. Accepts RGB color codes e.g #000000 Yes - if extra_rel = true otherwise no
specify_widget Defines the widget to be launched when the specify_info is clicked. A date_picker will lauch a datepicker but any other widget type e.g native_radio check_box will launch a subform
secondary_suffix Specifies the text to be displayed after the subform/date_picker values e.g 88 bpm Yes - if extra_rel = true otherwise no
secondary_value Holds the values from the date_picker or subform. Only needed incase the field has a predifined entry otherwise its always auto generated/automatically added through code no
content_form Incase the popup required is a sub form this attributte holds the subform file name. Yes - if extra_rel = true & you need launch a subform otherwise no
openmrs_entity Holds the entity type on OpenMRS e.g Person, Address, Concept no
openmrs_entity_id Holds the concept id from OpenMRS no

Secondary value attributes

Field Attribute Usage Required
key Unique of the field on the subform yes
type Type of the field on the subform yes
values A JSON array of the selected/entered values of the specified widget/field yes

Seconday value values string design

Each string might have three parts for checkboxes. The three parts are as follows option_key:option_text:option_value e.g "rapid_breathing:Rapid breathing:true" Each string might have two parts for radio buttons & spinners. The two parts are as follows option_key:option_text e.g "rapid_breathing:Rapid breathing" Each string might have 1 part for edit texts & date pickers. The three parts are as follows entered/selected value e.g "Rapid breathing"

Example JSON

{
  "key": "native_radio_one",
  "openmrs_entity_parent": "",
  "openmrs_entity": "",
  "openmrs_entity_id": "",
  "type": "native_radio",
  "label": "User sub forms?",
  "label_text_style": "bold",
  "text_color": "#000000",
  "extra_rel": true,
  "has_extra_rel": "yes",
  "read_only" : true,
  "options": [
    {
      "key": "yes",
      "text": "Yes",
      "value": false,
      "openmrs_entity": "",
      "openmrs_entity_id": "",
      "specify_info": "User sub specify...",
      "specify_widget": "normal_edit_text",
      "specify_info_color": "#8C8C8C",
      "secondary_suffix": "bpm",
      "content_form": "user_native_sub_form"
    },
    {
      "key": "no",
      "text": "No",
      "value": false,
      "openmrs_entity": "",
      "openmrs_entity_id": ""
    }
  ],
  "v_required": {
    "value": true,
    "err": "Please specify user native form."
  },
  "relevance": {
    "rules-engine": {
      "ex-rules": {
        "rules-file": "sample-relevance-rules.yml"
      }
    }
  },
  "calculation": {
    "rules-engine": {
      "ex-rules": {
        "rules-file": "sample-calculation-rules.yml"
      }
    }
  }
}

Required Status

To make a field required add v_required attribute with value true. The text on the err attribute will be displayed to the user in case the field is not filled.

Rules

Calculations

  "calculation": {
    "rules-engine": {
      "ex-rules": {
        "rules-file": "sample-calculation-rules.yml"
      }
    }
  }

The block above shows the rules engine relevance block.

Relevance

"relevance": {
    "rules-engine": {
      "ex-rules": {
        "rules-file": "sample-relevance-rules.yml"
      }
    }
  }

The block above shows the rules engine relevance block.