Hide related field depending on the value of a Dropdown List(or other logic)?

Hello I wanted to hide two fields depending on a dropdown value:

System: Sugar Enterprise 7.8

Scenario:

Module where I want to hide: moduleA

On record/create view there is a dropdown: docType (values: typeB, typeC, both, none)

There is two related modules: moduleB, moduleC

Logic (trying to write as a pseudo code):

If the docType=typeB

   hide moduleC related field;

Else if the docType=typeC

   hide module B related field;

Else if the docType=none

   hide both related field;

Else if the docType=both

   do nothing, dont hide the related field;

There is a solution trough the create.js and record.js but a little bit old, and not detailed: How to hide a field in preview? 

Tried something like that but not works.

*record.js

({     extendsFrom: 'RecordView',      initialize: function (options) {
     this._super('initialize', [options]);this.model.on('hide:related',_showHideFields);     },
    
     _showHideFields:function(model, collection, fetch) {
          var docType = this.model.get('docType_c');// fetches  docType dropdown value
          if(doc_type === "typeB")
          {                   
               $('div[name="MOD_moduleA_MOD_moduleC_1_name"]').parent().hide();
          }         
          else if(doc_type === "typeC")
          {
               $('div[name="MOD_moduleA_MOD_moduleB_1_name"]').parent().hide();
          }    
     },    
})

There is missing something?

The code just not works.

Thank You for Your suggestions!

Regards,

Arpad

Parents
  • Hi Arpad Szabo

                           Have you tried using the onchange event

    Regards

    Sidhu

  • Arpad Szabo

    Small change of code as follows:

    ({     
      extendsFrom: 'RecordView',     
      initialize: function (options) {
         this._super('initialize', [options]);
         this.model.on("change:docType_c",this._showHideFields, this);    
      },
        
      _showHideFields:function(model, collection, fetch) {
              var docType = this.model.get('docType_c');// fetches  docType dropdown value
              if(doc_type === "typeB")
              {                   
                   $('div[name="MOD_moduleA_MOD_moduleC_1_name"]').parent().hide();
              }         
              else if(doc_type === "typeC")
              {
                   $('div[name="MOD_moduleA_MOD_moduleB_1_name"]').parent().hide();
              }    
         },    
    })

    You need to trigger onChange event. Place above code and check it once.

    Hope this Helps.

    Best Regards

    S Ramana Raju

Reply
  • Arpad Szabo

    Small change of code as follows:

    ({     
      extendsFrom: 'RecordView',     
      initialize: function (options) {
         this._super('initialize', [options]);
         this.model.on("change:docType_c",this._showHideFields, this);    
      },
        
      _showHideFields:function(model, collection, fetch) {
              var docType = this.model.get('docType_c');// fetches  docType dropdown value
              if(doc_type === "typeB")
              {                   
                   $('div[name="MOD_moduleA_MOD_moduleC_1_name"]').parent().hide();
              }         
              else if(doc_type === "typeC")
              {
                   $('div[name="MOD_moduleA_MOD_moduleB_1_name"]').parent().hide();
              }    
         },    
    })

    You need to trigger onChange event. Place above code and check it once.

    Hope this Helps.

    Best Regards

    S Ramana Raju

Children
No Data