add a visible formula on multiselect field

There is multiselect field "request_type" and a text area field "referred_by_other".

I want to add a visible formula on multiselect field:

when the value of "request_type" selected is “Other” only then "referred_by_other" field is visible. Please help.

Parents
  • You could play some tricks... 

    In your module's clients/base/fields/enum/enum.js you can listen for changes in the request_type multiselect field. 

    If "Other" is included then show the field, else hide it.

    I did something similar here where each of the options in a departments multi-select has it's own "details" field related to it and I want to display/hide those detail fields based on the selections.

    ({
    /*
    * custom/modules/Accounts/clients/base/fields/enum/enum.js
    * show/hide detail fields for departments using site license
    */

      extendsFrom: 'EnumField',
      initialize: function(opts){
        this._super('initialize',[opts]);
        this._initEvents();
      },
      _initEvents: function(){
          this._departmentDropdownFieldChange();
          this._detailsFieldsChange();
      },
      _departmentDropdownFieldChange: function() {
         if(this.name == 'department_using_sitelic_c'){
            this.on('render', this.triggerDetailFieldsChange, this);
            this.model.on('change:'+ this.name, this.triggerDetailFieldsChange,this);
         }
      },
      _detailsFieldsChange: function(){
         if(typeof(this.name) !== 'undefined' && this.name.match(/.*_details_c/)){
           this.model.on('parent:module:change', function(){
             this.items = {};
             this._render();
           }, this);
         }
      },
      triggerDetailFieldsChange: function(){
        var self = this;
        var selected = self.model.get('department_using_sitelic_c');
        if(selected){
         //I map the dropdown values to the field that needs to be displayed for each one of them
          var detailsMap = [
             {deptname:'Aerospace',deptfield:'aerospace_details_c'}
            ,{deptname:'ArtDesign',deptfield:'artdesign_details_c'}
            ,{deptname:'Bioengineering',deptfield:'bioengineering_details_c'}
    <...more here...>

          ];
          //create an array of selected trimmed values     
          selectedArray = [];
          $.each(selected, function (index, value){
            if(value !== ''){
              selectedArray.push(value.replace(/ /g,''));
             }
          });
          //if the array is not empty then show all selected fields and hide the others
          if (selectedArray.length > 0){
            for (var i in detailsMap) {
              //if the department name was selected show the corresponding department field
              if (selectedArray.indexOf(detailsMap[i].deptname) > -1) {
                $('span[data-fieldname="'+detailsMap[i].deptfield+'"]').show();
                $('.record-label[data-name="'+detailsMap[i].deptfield+'"]').show();
              }else{
                //otherwise hide it
                $('span[data-fieldname="'+detailsMap[i].deptfield+'"]').hide();
                $('.record-label[data-name="'+detailsMap[i].deptfield+'"]').hide();
              }
            }
            //if the array is empty then hide them all, we selected nothing
          }else{
            for (var i in detailsMap) {
              $('span[data-fieldname="'+detailsMap[i].deptfield+'"]').hide();
              $('.record-label[data-name="'+detailsMap[i].deptfield+'"]').hide();
            }
          }
        }
        this.model.trigger('parent:module:change');
      },
    })

    FrancescaS

  • Thank you for your reply. How can we make the "referred_by_other" field required when it is shown?

Reply Children
No Data