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

TFischer
Tera Expert

Hi Revathi,

 

It sounds like you are describing a table with multiple select inputs, but I just see one in your code. Are all the inputs mapped to the same ng-model, c.data.manager_action?

Yes @TFischer . I need help understanding how to add a different ng-model each time. 

TFischer
Tera Expert

Sure, I can't be certain without seeing your full html and client script but I'm assuming that the other select inputs are bound to the same ng-model, which is telling your inputs that all they should all share the same value.

 

If your inputs require unique values, they need unique ng-model variables. If you are rendering rows in a table with ng-repeat, that's not going to work. 

 

I would need to see the html template and client script to help you find a more specific solution.

 

 

Revathi Kotha
Tera Contributor
HTML Script:

<form>
  

<div>
 <button class="test" class="btn btn-primary btn-block" ng-click="c.uiAction('remove')">Keep All</button>
 <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 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="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> 
       
    </tr>  

  </table>
 
  
</div>
  
  </form>



Client Script:


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

	c.changeAction=function(number)
	{
		
		c.data.empnumber=number.toString();
		c.data.action=c.data.manager_action.value.toString();
		
				
		
		if(number!='')
		{		

			if(c.data.manager_action.value=='2')
			{

				spModal.open({
					title: 'Reason for deactivating CW',
					buttons:[],
					widget: 'cwdeactivation',
					widgetInput: {sys_id:number,action:'Remove'}

				}).then(function(response) {
					
					
				});
				
			}
			else if(c.data.manager_action.value=='1')
				{
					c.server.update();
				}
			
		}
		
			
		}

	};