Change options in a dropdown field when a relate field changes

Hi All,

            Can you update how to change the drop down field when a relate field changes.

On change event we are checking the condition and doing as below:

relate field == 'xyz' then dropdown field = a,b,c as options in the drop down list

if relate field ==' mno' then dropdown field = d,e,f as options in  the drop down list.

1.We are able to get options but unable to update in the dropdown list when the relate field changes.

When we tried with below code:

this.model.fields['ds_c'].options = divSub_value_list;
this._super("_render"); 

above code it is rendering full view,with this we are getting problem with show and hide fields through formula.

2.When we are trying with particular field render with below code the drop down list is not updating.

    var renderField = this.getField('<field_name>');  
    renderField.render(); 

So how to update the dropdown list options based on relate field change.i am using version 7.6.1.0 ENT

Francesca Shiekh Ramana Raju Santhana Mehul  Bhandari Bhavesh Patel Angel Magana

 David López

Regards

Sidhu

Parents Reply Children
  • Hi sidhu sidhu,

    I can show you a working example which changes the options of a dropdown list when another field changes its value.

    Let's say your module is Accounts, so you would create the following file: custom/modules/Accounts/clients/base/fields/enum/enum.js with the below content:

    ({

        extendsFrom: 'EnumField',
        initialize: function(opts){
            this._super('initialize',[opts]);
            this._initEvents();
        },

        _initEvents: function(){
            this._changeIndustry();
        },

        _changeIndustry: function() {
            this.model.on("change:account_type", this.changeIndustryHandler, this);
        },

        changeIndustryHandler: function(){
            var self = this;
            if (self.name === 'industry') {
                var newOptions = {
                    'Apparel': 'Apparel'
                };
                self.items = newOptions;
            }
        }
    })

    As you see here, I am handling the event change:account type, which triggers the function changeIndustryHandler when the value of the field account_type changes.

    There, I am changing the options (self.items) of the Dropdown.

    You should adapt this code in order to handle the event of the change of your relate field and change the options of the dropdown as desired.

    If you need further clarification do not hesitate to ask me.

    Hope it helps!

    Regards,

    David.

  • Hi Mehul  Bhandari

    Your reference links i already gone through, but those will work on rendering of the page.

    But i want onChange event on Account Name which is of relate type and when it is changed new option should be update in my dropdown field called dropdown_sub_name_c.

    Example:

    Two fields:

    1. account_name is of type "relate field", with values { Persons, Colors, Flowers }

    2. dropdown_sub_name_c is of type dropdown with list name as "dropdown_sub_name_dom" with values { "":"", "John":"John", "Glen":"Glen", "Red":"Red", "Green":"Green", "Jasmine":"Jasmine", "Rose":"Rose"}

    Requirement:

    When i change account_name, based on the value/option selected my dropdown_sub_name_c should be changed i.e

    1. account_name == Persons then i need to get only dropdown_sub_name_c == {"":"", "John":"John", "Glen":"Glen"}

    2. account_name == Colors then i need to get only dropdown_sub_name_c == {"":"", "Red":"Red", "Green":"Green"}

    3. account_name == Flowers then i need to get only dropdown_sub_name_c == {"":"", "Jasmine":"Jasmine", "Rose":"Rose"}

     

    Regards

    Sidhu