The CreatorCon Call for Content is officially open! Get started here.

Real-time update of select field in widget once another field changes value

Nen
Tera Guru

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

Nen_1-1664851402143.png

 

 

Nen_0-1664851318433.png

 

Any help will be greatly appreciated.

 

Thank you!

 

 

2 REPLIES 2

Rahul RJ
Giga Sage

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.

RJ34_0-1664854036982.png

 

Thanks,
Rahul

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