AnsweredAssumed Answered

Dynamic Dropdown in Quoted line item

Question asked by Sundar Kumar on Dec 23, 2019
Latest reply on Dec 26, 2019 by Francesca Shiekh

I want to populate the drop-down values dynamically based on other field value selected in Quoted Line Item. I have add ed my changes in following path: custom/modules/Products/clients/base/fields/enum/enum.js.

 

OnChange of product_template_id field, i want to display Status (custom field) drop-down options in Quoted Line Item.

for ex. if i am selecting product_tempalte_id as "Lindsay Gadget" and same value should be auto selected in Status and few other additional options should be shown based on certain conditions in Quoted Line Item. I am getting the dd values from api and trying to populate those results as dropdown options for Status field.

 

The below changes are working fine for first two line items, but if i am adding third one, 1st line item option value is changed to blank and its displaying the same (line Item 3) dd option list for all the line-items.

 

({
extendsFrom:'EnumField',
initialize: function(options){
this._super('initialize',[options]);
this.type ='enum';
this.listenTo(this.model,"sync",function(model){
this.loadOptions();
});
this._initEvents();

},

_initEvents:function(){
//console.log('_initEvents');
this._updateStatus();
},

_updateStatus:function(){
this.model.on('change:product_template_name',this.loadOptions, this);
},


loadOptions: function(callback) {
var product_template_id = this.model.get('product_template_id')
if(this.name === 'status_c'){
var options = {};
var self = this;
var request;
var _itemsKey = 'cache:' + this.module + ':' + this.name + ':items';
var _key = 'request:' + this.module + ':' + this.name;
if (!this.context.get(_key)) {
//if(this.model.get('product_template_id')){
dataArray ={'product_template_id':product_template_id}
app.api.call('create', app.api.buildURL('Products/getStatus'), dataArray, {
success: function(o) {
if (self.disposed) {
return;
}
if (self.items !== o) {
self.items = o;
self.context.set(_itemsKey, self.items);
//self.context.unset(_key);
//if (callback) callback.call(self);
if (!_.isUndefined(self.items)) {
if (Object.keys(self.items).length == 1) {
self.model.set(self.name, Object.keys(self.items)[0]);
} else if (!(self.model.get(self.name) in self.items)) {
self.model.set(self.name, product_template_id);
}
}
}
},
error: function(e) {
if (self.disposed) {
return;
}

if (error) {
error(e);
}

// Continue to use Sugar7's default error handler.
if (_.isFunction(app.api.defaultErrorHandler)) {
app.api.defaultErrorHandler(e);
}

self.items = {'': app.lang.get('LBL_NO_DATA', self.module)};
},
complete: function() {
if (!self.disposed) {
self.context.unset(_key);
callback.call(self);
}
}
});
//}//product template ends
}
}//uom_c ends
},

loadEnumOptions:function(fetch, callback){
var self=this;
var _itemsKey = 'cache:'+this.module+':'+this.name+':items';
this.items = this.context.get(_itemsKey);
if(!this.items){
this.isFetchingOptions = true;
var _key = 'request:'+this.module+':'+this.name;
if(this.context.get(_key)){
var request = this.context.get(_key);
request.xhr.done(_.bind(function(data){
if(this.items !== data){
this.items = data;
callback.call(this);
}
},this));

}else{
this.loadOptions(callback);
}
}
},
})

 

 

Any help is appreciated,

Thanks,

Kumar

Attachments

Outcomes