Real-time update of select field in widget once another field changes value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2022 07:48 PM
Hi All,
I'm working on a custom portal widget and the requirement is to automatically update the State to "Work in Progress" once the user selects an option on the Assigned to field. I know I can do this via Business Rule but the users wanted to see the State update real-time on the form view.
I'm new to widgets and I'm not sure how to do this. So far, I was able to track the change to the Assigned to field using "ng-change" but I'm not sure how to update the value of the State field without having to save the form first.
I've seen the below code on the Client Script (for a different purpose) so I thought I can make it work with something similar for state.
Client Script
$scope.server.update().then(function(r) {
$scope.data.action = null;
$scope.data.record.state.value = 'work_in_progress';
$scope.data.record.state.display_value = 'Work in Progress';
$timeout(function(){
$scope.clearSelectInput('state');
});
});
console.log($scope.data.record);
Link function
scope.clearSelectInput = function(name) {
var input = $('select[name="' + name + '"]');
if (input)
input.val('').trigger('change');
}
I was only able to change to value of the $scope.data.record but not the currently selected value of the State select box
Any help will be greatly appreciated.
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2022 08:22 PM - edited 10-03-2022 08:27 PM
Hi,
You need to use the client controller field. change function to check assigned_to field value changed and based on that event you can call server-side code to update the state of the records.
Thanks,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2022 10:19 PM
Hi Rahul,
Thank you for the reply. I tried the solution you provided above and it updated the State field but I need to reload the page first before seeing the said change.
Is there a way to update the state field real-time without having the user reload the page?
Regards,
Nen