Update multiple select is not keeping its selections if i am going to another todo and then back

Niklas6
Tera Expert

I have a multiple select in a todo widget with some options selected. If I go to another todo in the list and then back, whatever was selected is not selected anymore. 

 

HMTL Snippet: 

 

{{c.data.u_applicable_checklist2}}
<select id="u_applicable_checklist" ng-options="opt.id as opt.name for opt in options2" class="dropdown form-control" ng-model="c.data.u_applicable_checklist2" multiple></select>

 

 

Server code: 

 

if(!input && options){  
	data.multiSelectOptions = getChoiceListOptions('x_mscs2_occupation_task', 'u_applicable_checklist', 'multiselect');	//Returns all options to the select list				

	data.u_applicable_checklist2 = ohsTask.getValue('u_applicable_checklist');	//Returns the selected values in JSON format: {"office":{"name":"Office","id":"office"},"checklist":{"name":"Checklist","id":"checklist"},"chemical_hazards":{"name":"Chemical hazards","id":"chemical_hazards"}}

}

 

 

Client controller code:

 

var c = this;			
$scope.options2 = {};	//Need to do this or the code will break when revisting the widget
if(c.data.taskType == 'safety_audit' || c.data.taskType == 'yearly_ohs_meeting'){

	$scope.options2 = JSON.parse(c.data.multiSelectOptions);				
	c.data.u_applicable_checklist = c.data.u_applicable_checklist2.split(',');						

}

 

 

When I reload the page and the widget is loaded, options are populate as they should and the saved selections are marked in the list. The text in the curly brackets prints the actually value(s) of the selections. 

 

If I go to another widget and then back, the saved values are not selected anymore but the curly brackets still prints the proper value. 

 

If I change the ng-model (and inside curly brackets) to c.data.u_applicable_checklist (se html after this section), nothing is presented from the curly brackets and no options are marked the second time I visit the widget but the first time the brackets prints the values and the selections are marked. 

 

 

{{c.data.u_applicable_checklist}}
<select id="u_applicable_checklist" ng-options="opt.id as opt.name for opt in options" class="dropdown form-control" ng-model="c.data.u_applicable_checklist2" multiple></select>

 

 

I tried to use c.data.u_applicable_checklist instead of c.data.u_applicable_checklist2 as a variable on the server side and updated so there is no c.data.u_applicable_checklist2 in the client controller or the html part. When doing this the second time I visit the widget c.data.u_applicable_checklist has converted to an object. I guess the variables in the widget isn't reset when jumping between the todos without refreshing the entire page. 

 

How come the select isn't getting the options selected the second time I visit the widget and how can I ensure that it does? 

0 REPLIES 0