- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 08:42 AM
Hello Everyone,
How do I update all the select box options to a value when I click on a button on the widget?
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="y.name for y in c.data.actions" ng-required="true">
</select>
</td>
</tr>
</table>
<button class="test" class="btn btn-primary btn-block" ng-click="c.selectAll()">Keep All</button>
<br/>
<br/>
</div>
Client Script :
api.controller=function($scope,spModal) {
/* widget controller */
var c = this;
c.data.actions=[{
name:'Keep',
value:'1'
},
{
name:'Remove',
value:'2'
}]
var selectedrecords=[];
selectedrecords=c.data.arr;
var employeenumbers=[];
for(var j=0;j<selectedrecords.length;j++)
{
employeenumbers.push((selectedrecords[j].employee_number));
}
c.selectAll=function(rec)
{
}
c.changeAction=function(number,actiontaken)
{
// alert(actiontaken);
c.data.number=number;
c.data.action=actiontaken.value;
$scope.page.g_form.setValue('audited_records',employeenumbers);
if(number!='')
{
if(actiontaken.value=='2')
{
spModal.open({
title: 'Reason for deactivating CW',
buttons:[],
widget: 'cwdeactivation',
widgetInput: {sys_id:number,action:'Remove'}
}).then(function(response) {
});
}
else if(actiontaken.value=='1')
{
c.server.update();
}
}
}
};
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 08:37 AM
Hi @Revathi Kotha ,
To update all the select box options to a specific value when clicking on the button in your widget, you can modify the selectAll function in your client script to loop through all the items and update the manager_action value.
Updated selectAll Function:
c.selectAll = function() {
for (var i = 0; i < c.data.arr.length; i++) {
c.data.arr[i].manager_action = c.data.actions[0]; // Set the value to 'Keep' or whichever action you prefer
c.changeAction(c.data.arr[i].employee_number, c.data.actions[0]);
}
};
This code will iterate over all the items in c.data.arr and set their manager_action to the value "Keep" (or any action you'd like to assign). The changeAction function is then called to handle the update logic.
Thanks & Regards,
Siddhesh Jadhav
If this solves your query, please mark it as helpful and accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 08:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 08:37 AM
Hi @Revathi Kotha ,
To update all the select box options to a specific value when clicking on the button in your widget, you can modify the selectAll function in your client script to loop through all the items and update the manager_action value.
Updated selectAll Function:
c.selectAll = function() {
for (var i = 0; i < c.data.arr.length; i++) {
c.data.arr[i].manager_action = c.data.actions[0]; // Set the value to 'Keep' or whichever action you prefer
c.changeAction(c.data.arr[i].employee_number, c.data.actions[0]);
}
};
This code will iterate over all the items in c.data.arr and set their manager_action to the value "Keep" (or any action you'd like to assign). The changeAction function is then called to handle the update logic.
Thanks & Regards,
Siddhesh Jadhav
If this solves your query, please mark it as helpful and accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 08:44 AM
@Siddhesh Jadhav Thank you so much.It worked. I am new to widgets and struggled to get the value of action .Now I understand that
c.data.actions[0]
The information below helps me get the value.