SugarCRM 7  How can I re-render a multi enum?

I want to change the dropdown options on a multi-enum (descriptors) based on another dropdown (product).

Dependencies and visibility grids don't help here because they don't work on multienum (as far as I know).

I have gotten as far as changing the options property on the filed but it won't render the new list on change.


 
   extendsFrom: 'RecordView',     initialize: function(options){
      this._super('initialize', [options]);
      this.model.on('change:case_product_c', this.toggleDescriptors, this);
   },
   render: function()
   {
      this._super('render');
   },
   toggleDescriptors : function(){
     var case_descriptor_c = this.model.fields['case_descriptor_c'],
     descriptor_dropdown = 'case_'+this.model.get('case_product_c').replace(' ','_') +'_descriptor_dd';
     case_descriptor_c.options = descriptor_dropdown;
     console.log(case_descriptor_c);
   },
                         
The above code works to set the dropdown correctly when the page first loads (the dropdpwn contains the right items based on the selected product of the record being loaded), but when I change the product it changes the case_descriptor_c.options (I have verified this in the log) but not the actual values displayed (when I click in the box I get the old list again)...

I believe I have to render the field again, but I don't know how...
Any hints?

thanks,
FrancescaS
Parents
  • Hi FrancescaS,

    I don't know if this is the best solution but when i try and create dynamic dropdown option based on other fields in the view i would do something like this
    ({
    extendsFrom:'RecordView',
    originalDDOption: null,
    initialize: function(opts){
        this._super('initialize',[opts];
        this._setDDOption();
    },
    _setDDOption(){
      var newDDOption = null
       if(!this.originalDDOption){
         newDDOption = this.originalDDOption = _.clone(app.metadata._dev_data.app_list_strings['(list_dom_here)']);
      } else {
         newDDOption = _.clone(this.originalDDOption);
      } 
      //process your dropdown option list here
      app.metadata._dev_data.app_list_strings['(list_dom_here)'] = newDDOption;
      //i always keep a copy of my original dropdown option so that i could revert the option if needed
    }
    })
    Hope this helped in some ways
  • Very timely comment Adinu, I just upgraded to 7.6 and mine broke :(

    I get an error: Cannot read property 'app_list_strings' of undefined for that exact line:
    app.metadata._dev_data.app_list_strings['case_descriptor_dd'] 

    And the user gets a notice that the field case_product_c cannot be rendered which is not a particularly correct error considering that it rendered that field just fine, it was the descriptor field that could not be rendered.

    this.items, in my case, doesn't work because I am not trying to replace the items for the case_product_c field but rather the items for the case_descriptor_c field.
    'this', in my case, is the product field which triggers the change in the descriptor field.

    Trying to find a solution... I'll update when I get one.

    thanks,
    FrancescaS
Reply
  • Very timely comment Adinu, I just upgraded to 7.6 and mine broke :(

    I get an error: Cannot read property 'app_list_strings' of undefined for that exact line:
    app.metadata._dev_data.app_list_strings['case_descriptor_dd'] 

    And the user gets a notice that the field case_product_c cannot be rendered which is not a particularly correct error considering that it rendered that field just fine, it was the descriptor field that could not be rendered.

    this.items, in my case, doesn't work because I am not trying to replace the items for the case_product_c field but rather the items for the case_descriptor_c field.
    'this', in my case, is the product field which triggers the change in the descriptor field.

    Trying to find a solution... I'll update when I get one.

    thanks,
    FrancescaS
Children
No Data