Field with Dependant Parent Dropdown

Hi All,

I'm looking for some help on Dependant dropdown fields.

In Cases Module I have created a dropdown field (called '1') that is only visible when the Case Sub-Category field is equal to 'A'.

Dropdown field '1' is also the Dependant parent dropdown for MultiSelect field '2' (edit visibility is set).

However MultiSelect field '2' is always visible and I can not see a way to also make this visible only when Sub-Category field is equal to 'A' also. 

Rather than use Dependant option of Parent Dropdown is there a formula I can write that will make MultiSelect field '2' only visible when Sub-Category field is equal to 'A' and also only display specific options depending on the value in Dropdown field '1'?

Hope this makes sense, any help would be appreciated.

Regards

Paul

Parents
  • Showing/hiding fields based on a dropdown is a simple visibility formula and if I read this correctly you can just use those to make fields appear/disappear.

    To change the multiselect options based on a dropdown is the tricky part.

    As far as I know there is no "formula" to do that and it requires code.

    This is what I did in custom/modules/Cases/clients/base/fields/enum/enum.js

    It should be relatively self explanatory with the inline comments.

    We have a products dropdown and a descriptor multi-dropdown.
    Depending on the product selected in the product dropdown we want different a different set of values available in the multi-dropdown.
    If there are no options for that product we just hide the descriptor multi-dropdown.

    // When the product (case_product_c) changes, 
    // change the options available in the multienum for case_descriptor_c
    
    // Note that we have one dropdown per product defined in the language file
    // the format of the dropdown name is case_<product>_descriptor_dd to match the allowable
    // values to the product.
    
    ({
      extendsFrom: 'EnumField',
      initialize: function(opts){
        this._super('initialize',[opts]);
        if (this.view.action !== 'filter-rows'){
          this._initEvents();
        }
      },
      _initEvents: function(){
          this._productDropdownFieldChange();
          this._descriptorDropdownFieldChange();
      },
      //define the on.change and render events for the case product
      _productDropdownFieldChange: function() {
         if(this.name == 'case_product_c'){
            //trigger changing descriptor dropdown when product is loaded
            this.on('render', this.triggerDescriptorFieldChange, this);
            //trigger changing descriptor dropdown when product changes 
            this.model.on('change:'+ this.name, this.triggerDescriptorFieldChange,this);
         }
      },
      //define the on.change event for the case descriptor so we have a way to call it
      _descriptorDropdownFieldChange: function(){
         if(this.name  == 'case_descriptor_c'){
           this.model.on('parent:module:change', function(product_descriptor_dd){
             //check if the descriptor exists/has values
             //if so, load the values and re-render
             ddOptions = app.lang.getAppListStrings(product_descriptor_dd);
             if(!(_.isUndefined(ddOptions)) && !(_.isEmpty(ddOptions))){
                $('span[data-fieldname="case_descriptor_c"]').show();
                $('.record-label[data-name="case_descriptor_c"]').show();
               this.def.options =ddOptions;
               this.items={};
               this._render();
             //if there are no valid items in the list or the list is empty then
             //hide the field
             }else{
               $('span[data-fieldname="case_descriptor_c"]').hide();
               $('.record-label[data-name="case_descriptor_c"]').hide();
             }
           }, this);
         }
      },
      triggerDescriptorFieldChange: function(){
        //check if the descriptor is on the form.
        if(!_.isUndefined(this.model.get('case_descriptor_c'))){
          var product_descriptor_dd = '';
          if(!_.isUndefined(this.model.get('case_product_c')) && !_.isEmpty(this.model.get('case_product_c'))){
            //the name of the DD is case_<productName>_descriptor_dd
            var product = this.model.get('case_product_c').replace(/\s+/g, "_");
            product_descriptor_dd = 'case_'+product+'_descriptor_dd';
          }
          //set options to the product specific dropdown
          this.model.trigger('parent:module:change',[product_descriptor_dd]);
        }
      },
      _dispose: function() {
        this._super('_dispose');
      },
    })

    This is v7 code, it's not perfect, and can probably use a more expert review than me... But so far it has worked well for us.

    We're on v11.0.1 Professional On-site.

    FrancescaS

Reply
  • Showing/hiding fields based on a dropdown is a simple visibility formula and if I read this correctly you can just use those to make fields appear/disappear.

    To change the multiselect options based on a dropdown is the tricky part.

    As far as I know there is no "formula" to do that and it requires code.

    This is what I did in custom/modules/Cases/clients/base/fields/enum/enum.js

    It should be relatively self explanatory with the inline comments.

    We have a products dropdown and a descriptor multi-dropdown.
    Depending on the product selected in the product dropdown we want different a different set of values available in the multi-dropdown.
    If there are no options for that product we just hide the descriptor multi-dropdown.

    // When the product (case_product_c) changes, 
    // change the options available in the multienum for case_descriptor_c
    
    // Note that we have one dropdown per product defined in the language file
    // the format of the dropdown name is case_<product>_descriptor_dd to match the allowable
    // values to the product.
    
    ({
      extendsFrom: 'EnumField',
      initialize: function(opts){
        this._super('initialize',[opts]);
        if (this.view.action !== 'filter-rows'){
          this._initEvents();
        }
      },
      _initEvents: function(){
          this._productDropdownFieldChange();
          this._descriptorDropdownFieldChange();
      },
      //define the on.change and render events for the case product
      _productDropdownFieldChange: function() {
         if(this.name == 'case_product_c'){
            //trigger changing descriptor dropdown when product is loaded
            this.on('render', this.triggerDescriptorFieldChange, this);
            //trigger changing descriptor dropdown when product changes 
            this.model.on('change:'+ this.name, this.triggerDescriptorFieldChange,this);
         }
      },
      //define the on.change event for the case descriptor so we have a way to call it
      _descriptorDropdownFieldChange: function(){
         if(this.name  == 'case_descriptor_c'){
           this.model.on('parent:module:change', function(product_descriptor_dd){
             //check if the descriptor exists/has values
             //if so, load the values and re-render
             ddOptions = app.lang.getAppListStrings(product_descriptor_dd);
             if(!(_.isUndefined(ddOptions)) && !(_.isEmpty(ddOptions))){
                $('span[data-fieldname="case_descriptor_c"]').show();
                $('.record-label[data-name="case_descriptor_c"]').show();
               this.def.options =ddOptions;
               this.items={};
               this._render();
             //if there are no valid items in the list or the list is empty then
             //hide the field
             }else{
               $('span[data-fieldname="case_descriptor_c"]').hide();
               $('.record-label[data-name="case_descriptor_c"]').hide();
             }
           }, this);
         }
      },
      triggerDescriptorFieldChange: function(){
        //check if the descriptor is on the form.
        if(!_.isUndefined(this.model.get('case_descriptor_c'))){
          var product_descriptor_dd = '';
          if(!_.isUndefined(this.model.get('case_product_c')) && !_.isEmpty(this.model.get('case_product_c'))){
            //the name of the DD is case_<productName>_descriptor_dd
            var product = this.model.get('case_product_c').replace(/\s+/g, "_");
            product_descriptor_dd = 'case_'+product+'_descriptor_dd';
          }
          //set options to the product specific dropdown
          this.model.trigger('parent:module:change',[product_descriptor_dd]);
        }
      },
      _dispose: function() {
        this._super('_dispose');
      },
    })

    This is v7 code, it's not perfect, and can probably use a more expert review than me... But so far it has worked well for us.

    We're on v11.0.1 Professional On-site.

    FrancescaS

Children