Francesca Shiekh

Dynamic Dropdown renders but does not save?

Discussion created by Francesca Shiekh on Sep 18, 2016
Latest reply on Oct 13, 2016 by Francesca Shiekh

I am building a custom Scoring module with a dynamically populated dropdowns.

 

Simplifying the picture to get to the point:

I have a score_field enum with a dynamic dropdown list of field names for a given module (field name => label).

 

When a score_field is chosen, a modification to the enum field type for the Scoring module changes the score_field_value field's multienum dropdown options to the list of options of the corresponding score_field in the original module.

 

For example, I choose Leads as the module, when I set the score_field = "status" the dropdown options for the multienum score_field_value are set to lead_status_dom.

 

So far so good. I see the correct list of fields in score_field_value and can choose those values and populate the multienum.

 

The problem is when I Save the Scoring record, it saves the score_field correctly as "status" but does not save the score_field_values I chose from the lead_status_dom. They are not visible from the front end and are not set in the corresponding database record and I can't figure out why.

 

I have used this method before but it has always been to restrict an existing dropdown list to a subset of said list. I suspect the problem is that the original placeholder list doesn't have any of these values and there is some validation during the save process that is preventing me from using these "new" values.

 

So the question is: Is there validation of the enum values prior to saving that I need to somehow override to get this to work?

 

custom/modules/wsco_ScoreCriteria/clients/base/fields/enum/enum.js

 

({
  extendsFrom: 'EnumField',
  initialize: function(opts){
    this._super('initialize',[opts]);
    this.initEvents();
  },
  initEvents: function(){
      this.score_fieldDropdownFieldChange();
      this.enumDropdownFieldsChange();
  },
  score_fieldDropdownFieldChange: function() {
     //when score_field is changed look up the proper values for the dropdowns
     if(this.name == 'score_field'){
        //trigger when score_field is loaded
        this.on('render', this.triggerEnumDropdownFieldsChange, this);
        //trigger when score_field changes 
        this.model.on('change:'+ this.name, this.triggerEnumDropdownFieldsChange,this);
     }
  },
  enumDropdownFieldsChange: function(){
     if(this.name == 'score_field_value'){
           this.model.on('parent:module:change', function(ddOptions){
             var opts = {};
             if(this.name == 'score_field_value'){
                if(!_.isUndefined(ddOptions) && !_.isEmpty(ddOptions)){
                   //show the dropdown //hide the text
                   $('span[data-fieldname="scorefield_value_text"]').hide();
                   $('.record-label[data-name="scorefield_value_text"]').hide();
                   this.def.options = ddOptions;
                   this.items = {};
                   this.render();
                }else{
                   //no options
                   //hide the dropdown //show the text
                   $('span[data-fieldname="score_field_value"]').hide();
                   $('.record-label[data-name="score_field_value"]').hide();
                   $('span[data-fieldname="scorefield_value_text"]').show();
                   $('.record-label[data-name="scorefield_value_text"]').show();
                }
             }
           }, this);
     }
  },
  triggerEnumDropdownFieldsChange: function(){
     var ddOptions = '',
         self = this,
         score_field = self.model.get('score_field'),
         scoring_id = self.model.get('wsco_scorecriteria_wsco_scoringwsco_scoring_ida'),
         scoringBean = app.data.createBean('wsco_Scoring', {id:scoring_id}),
         requestParent = scoringBean.fetch();
     requestParent.xhr.done(function(){
        var scoring_module = scoringBean.get('scoring_module'),
            scoringModuleMeta = app.metadata.getModule(scoring_module);
        if(!_.isUndefined(scoringModuleMeta.fields[score_field].options)){
            //ddOptions = app.lang.getAppListStrings(scoringModuleMeta.fields[score_field].options);
            ddOptions = scoringModuleMeta.fields[score_field].options;
            self.model.trigger('parent:module:change',ddOptions);
        }
     });
  },
})

 

Any help is appreciated,

thanks,
FrancescaS

Outcomes