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

  • 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 David López , Mehul  Bhandari

                      We will try your suggestions and get back to you.

    Regards

    Sidhu

  • Hi David López

    When we tried with your approach we got empty dropdown options.

    But when we console and check then we are able to see opitons in that but values are not updating on the dropdown list.

    Following are the steps and code we followed:

    1. We created as you said custom/modules/Cases/clients/base/fields/DropEnum/DropEnum.js 

     ({

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

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

        _changeAccounts: function() {
            this.model.on("change:account_name", this.changeDropdownHandler, this);
        },

        changeDropdownHandler: function(){
         console.log("Am from changeDropdownHandler");
            var self = this;
            console.log(self.name,"Am from changeDropdownHandler and Name");
            if (self.name === 'dropdown_sub_name_c') {
                var newOptions = {
              '':'',
                    'John': 'John',
                    'Glen':'Glen'
                };
                self.items = newOptions;
                self.render();
                console.log(self.items,"Am from changeDropdownHandler as Items");
            }
            console.log(self,"Am from changeDropdownHandler as self values...");
        }
    })

    In custom/modules/Cases/clients/base/views/record/record.php

                  3 => 
                  array (
                    'name' => 'dropdown_sub_name_c',
                    'type' => 'customDropEnum',
                    'studio' => 'visible',
                    'label' => 'LBL_DROPDOWN_SUB_NAME',
                  ),

     

    I have run Quick R&R.

    I need the option should be updated in the dropdown list when Account Name is changed.

    Regards

    Sidhu

  • 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

  • Hi sidhu sidhu,

    The example I provided to you works and it updates in the dropdown list the items.

    The only strange things that I see in your code are:

    1. You are calling the folder and file DropEnum and DropEnum.js; mines are called enum and enum.js and they work.
    2. What is the type customDropEnum in your record.php? Are you using a custom type instead of the default enum type one?

    Could you try the exact example am I providing to you? That way you could check that it works as expected and you may adapt it to your requirements.

    Regards,

    David.

  • Hi David López

                       Thanks for the update...my team members were checking with the thread...by the ways i will check your suggestions with them.

    Regards

    Sidhu

  • Hi David López

      

                               We have fixed it.Thank you for the suggestions.

    Regards

    Sidhu