How do I dynamically change a list on a CreateView

I want to change the list of status on the Case create view based on a selection made from a drop down list and the role of a user.  I currently have code running which should do this. It will successfully fire when the form is initiated but it does not fire when the triggering field is changed.  I want to change the status list each time the et_case_type field is changed.

initialize: function (options) {

        this._super("initialize", [options]);

        //this.checkRole();

       

        this.model.on('change:et_case_type',this.checkRole(), this);

},

    checkRole: function() {

        var self = this;

  

        app.api.call('read', app.api.buildURL('Users/check_role_membership/' + encodeURIComponent('Archive Cases')),

            null,

            {

                success: function(res) {

                    if (res.isEnabledRole && !res.isAdmin) {

                        var case_statuses = app.lang.getAppListStrings('case_status_dom');

                        var isFCST = app.user.get('roles').indexOf("Fleet Customer Services");

                        var isMobile = false;

                        if(self.model.get('et_case_type') == 1 || !self.model.get('et_case_type'))

                        {

                            isMobile = true;

                        };

                        if(isFCST != -1 && isMobile != true)

                        {

                            delete case_statuses['Closed_for_Customer'];

                            delete case_statuses['Closed_for_Ops'];

                            delete case_statuses['Closed_for_Kwikfit'];

                        }

                       

                        delete case_statuses['Closed_for_Kwikfit'];

                        self.model.fields['status'].options = case_statuses;

                        self.render();

                    }

                   

                },

                error: function(error) {}

            }

        )

    },

Parents
  • Hi Jason,

    You didn't declare in which file you are making the changes but i will go through how you can accomplish this.

    I would do this starting with duplicating ./modules/Cases/clients/base/fields/enum/enum.js into custom folder like; '/custom/modules/Cases/clients/base/fields/enum/enum.js'.

    ({
         extendsFrom: 'EnumField',
         initialize: function (options) {
              this._super("initialize", [options]);
         },
    
    
        render: function() {
            this._super('render');
            // this.name is dropdown name in your example; 
            if (this.name == 'case_status_dom' && this.view.currentState == "create") {
                // make the changes here and 
                // assign it to this.items.
                this.items = changedObject;
            }
         },
    })
    

    This should work for you.

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Hi Jason

    We can trigger a function on a field when we change is by this.events to do it

    in initialize: function()

    After this._super("initialize", [options]);

    this.events['change input[name=your-fieldname]'] = 'checkRole';

    I hope that helps

    Best Regards

    S Ramana Raju

  • Hi Jason,

    I haven't check your checkRole function but you mention that it is triggering while it is initiated and its changing the status list.

    this.model.on() will trigger only when form is initiated / Load... If you are sure that it is triggering the function when initiated then use my code, am dam sure it will trigger checkRole function. You can also check whether function is triggered by adding console.log("Am triggered in checkRole"); in it.

    I hope that helps

    Best Regards

    S Ramana Raju

Reply
  • Hi Jason,

    I haven't check your checkRole function but you mention that it is triggering while it is initiated and its changing the status list.

    this.model.on() will trigger only when form is initiated / Load... If you are sure that it is triggering the function when initiated then use my code, am dam sure it will trigger checkRole function. You can also check whether function is triggered by adding console.log("Am triggered in checkRole"); in it.

    I hope that helps

    Best Regards

    S Ramana Raju

Children
No Data