Service Portal - Issue with the selectboxes and the ng-repeat is not working

Revathi Kotha
Tera Contributor

 

Hello All,
When one select box value is selected, the other select box values in the table are changed. Is there anything wrong with the code?

 

HTML
 
 
<td><select id="manager_action" ng-model="c.data.manager_action" class="form-control" ng-change="c.changeAction({{x.employee_number}})" ng-options="y.name for y in data.actions" ng-required="true"> </select> </td>
 
Server Script: data.actions=[{ name:'Keep', value:'1' }, { name:'Remove', value:'2' }]

 

1 ACCEPTED SOLUTION

I'm assuming you want to prevent submission functionality if the required fields are not filled?

 

You need to add a name attribute to the form

<form name="formName">

 

Then check if the form is valid (all required fields are met) when the submit button is clicked

 <button class="test" class="btn btn-primary btn-block" ng-click="c.uiAction('remove')" ng-disabled="formName.$invalid">Keep All</button>

 

View solution in original post

23 REPLIES 23

Revathi Kotha
Tera Contributor

When the keep All button is clicked, I try to update the selection options to keep but fail to get the value of each select box.

You're wanting to change ALL the items in the array, right? So you don't need to grab the values individually. You can instead use the entire data.arr. It looks like your embedded modal widget is taking care of the logic for removing these items so I don't know what the requirement is, but whatever it is, I would assume it involves updating or deleting a u_non_employee record. 

 

This is something that you can achieve in your server side script.

Revathi Kotha
Tera Contributor

Yes, When Keep All button is clicked, I want to update all the CW records value to Keep.

 

The select box has two options: 'Keep' and 'Remove'. When the Remove option is selected, it will open another widget, and I will capture its reason. When Keep is selected, I update the backend record.

 

When Keep All is selected, I am trying to show the select box value as 'keep' but am struggling to get the selection's value from HTML.

 

I assigned both the select box options ' Keep' and Remove,' which do not come from the Server. That's why I don't understand how to capture the value from HTML.

 

@TFischer  As you suggested, I have updated the script below, but the value on the form is not updating. Any inputs?

Client script :

Client script:

api.controller=function($scope,spModal) {
	/* widget controller */
	var c = this;
	
//alert(c.data.manager_action);

	c.data.actions=[{
   
		name:'Keep',
		value:'1'

	},
	{
		name:'Remove',
		value:'2'
		
	}]
	
	

	c.selectAll=function()
	{
	
		for(var g=0;g<c.data.arr.length;g++)
				{
				  $scope.manager_action='1';
				}
			
		
		
		
	}
	
HTML:

<form name="formName">
 

<div>

 <br/>
  
 
  
  <table border="1px solid black">
     
    <tr>
     
      <th>Employee Number</th>
      <th>Employee Name</th>
      <th>Department</th>
      <th>Division</th>
      <th>End Date</th>
      <th>Action</th>
      
    </tr>
    <tr ng-repeat="x in c.data.arr">
      
      <td>{{x.employee_number}}</td>
      <td>{{x.u_name}}</td>
      <td>{{x.departmentname}}</td>
      <td>{{x.division}}</td> 
      <td>{{x.enddate}}</td>
      <td><select id="manager_action" ng-model="x.manager_action" 
                  class="form-control" ng-change="c.changeAction({{x.employee_number}},x.manager_action)" 
             ng-options="actions.name for actions in c.data.actions"> 
        
        </select>  
      </td> 
      
    </tr>  
    

  </table>
 <button class="test" class="btn btn-primary btn-block" ng-click="c.selectAll()">Keep All</button>
       
  <br/>
  <br/>
   
</div>


Server script:

if(!input)
		{
			data.manager='5a1d6d069750f950d8adb9e3a253af34';
	
								
	var arr=[];
			
	var gr=new GlideRecord('u_non_employee');
	gr.addEncodedQuery('u_manager='+data.manager+'^u_in_active=N');
	gr.query();
	while(gr.next())
	{
		var obj={};


		obj.manager=gr.u_manager.toString();
		obj.managername=gr.u_manager.getDisplayValue();
		obj.employee_number=gr.u_number.toString();
		obj.u_requestor=gr.u_requestor.toString();
		obj.requestorname=gr.u_requestor.getDisplayValue();
		obj.department=gr.u_department.toString();
		obj.departmentname=gr.u_department.getDisplayValue();
		obj.division=gr.u_division.toString();
		obj.u_name=gr.u_name.toString();
		obj.enddate=gr.u_enddate_system_format.toString();		
    obj.manager_action=""; 

		arr.push(obj);

	}

	data.arr=arr;
		}


})();

.