Conditional fields

Fields that are shown/hidden depending on values of other fields are called conditional fields. The conditional logic can be configured directly in the field, or it can be implemented with custom code.

If the conditional field depends only on one field, then it can be added in CB as a subfield, and the logic described in JSON config.

Example: the action template from demo core has a country field linked to a thesauri. When the country is selected, the city subfield appears with a list of cities for the selected country. The cities are added as children for country thesauri. The pictures bellow illustrate this:

Create city as a subfield of country and specify scope=variable & dependency" {}:


Assume we have list of organizations (a list of courts for ex). For the court we need to specify a list of judges that work there. Next: an organization publishes a decision. The decision will have an Objects field `court`. After selecting the court, a new field should appear to select the judge working in that court that made the decision.

Organization template

id pid name type cfg
1 NULL org_type objects
{"scope":  "17"      // assume a thesauri 'Organization type' is located below objectId==17
,"editor": "combo"}

2 1 judges objects
  "source": "tree"
  ,"scope": [2801]            // the judges are stored in a Contacts database
                              // located in folder with ID=2801
  ,"descendants": true        // fetch all children for folderId=2801 recursively
  ,"fq": ['country_id: 190']  // that have a "country_id" = 190. (make sure such a SOLR field exist)

  ,"templates": [69]          // judge templateId=69
                              // (Contacts folder may contain objects based on other
                              // templates, i.e. not only 'judges')

  ,"autoLoad": true           // loading the list of judges when editor is shown
  ,"renderer": "listObjIcons" // visually display a list of nodes with the icon
                              // specified in template config

  ,"maxInstances": 3          // allow up to 3 judges to be specified
  ,"editor": "form"           // shows a form with a list of judges
  ,"dependency": {
    "pidValues": [634]        // it means the `judges` field will appear only if
                              // the `org_type` field has value '634'
                              // 634 is the id of thesauri item meaning 'court'

Decision template

id pid name type cfg
20 NULL court objects
  "editor": "combo"
  "scope": [17]
21 20 judge objects
"source": "field"
,"field": "judge"            // the field of the parent node from which to load items
,"templates": [69]           // selects only judges(templateId=69) from the
                             // Court.Judges field
,"autoLoad": true            // loading the list of judges when editor is shown
,"renderer": "listObjIcons"  // visually display a list of nodes with the icon
                             // specified in template config
,"maxInstances": 3           // how many judge rows in the grid
,"editor":"combo"            // shows a drop down list of judges
,"dependency": {}

More Field examples todo

id pid name type cfg
15 8 city objects
{"scope": "76"    // shows children of objectId=76
,"dependency": {
    "pidValues": [62]  // the combo field will appear
                       // if parent_field (id: 8) is equal to 76
,"sort_order": "ord"   // ordered by position in thesauri list.
                       // other options: 'asc' or 'desc' by title

Custom source

An object field may depend on several other fields, or even on environment context (values depend on timezone, is the current day a holiday in a specific country etc).

Values of an object fields can be returned by a custom serverside function. If values depend on other fields, we need to specify which ones. Casebox will call the custom function with a JSON where all required fields are added.

  "source": {
    "requiredFields": "country,year"        // what fields to send when performing the AJAX call
    ,"fn": "coreName\\fields\\CustomSource.getValues"   // the serverside method
,"scope": 457

In this example, custom function "getValues" is called, located in class "CustomSource" from folder "fields" of the core directory.

CB will call "getValues" with

namespace coreName\fields;

class CustomSource
    public function getValues(&$p)
        // client side values in 'objFields'
        if (!empty($p['objFields']['country'])) {

            // 'fq' filters for SOLR
            $p['fq'] = array(
                'country:' . $p['objFields']['country']