- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2022 07:05 AM
Hi Team,
I have one question regarding $scope.$on question in widgets.
I see the function $scope.$on("field.change", function(evt, parms) { ... } is called only when the record picker is changed within the same widget.
Is it possible to invoke this function for other fields?
If not how can we trigger similar functionality for other fields?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2022 09:17 AM
I think in this case it wont work for text field
If you want to get the changes on text field or the value entered in the text field use ng-change directive in html code in input tag which is already there in your code and catch it in client side using ng-change function like below
<input type="text" ng-model='c.data.desc' id="description" class="form-control" ng-change="checkdescVal(c.data.desc)" required/>
// this is your text code
Write below code in your client controller
client controller:
$scope.checkdescVal = function(desc) // catch the parameter which contains changed text
{
alert(desc);
}
please try this and let me know
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2022 07:26 AM
Hello,
Yes you can invoke this for other fields also as below
$scope.$on("field.change", function(evt, parms) {
console.log(parms.field.name);
console.log(parms.newValue);
// do whatever you want to do here to refresh
// your data based on the changed value
});
if you can see in the above screenshot parms.field.name contains your field name and you can double check with your required field and if it satisfies the condition write yopur login inside IF loop
please accept this solution if this helps you in understanding how this works
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2022 08:10 AM
Hi Mohit,
Thanks a lot for your response.
It still doesnt call the client function to me. Just to explain a bit more. I have 2 fields on form.
One is record-picker for which this is called and another text field for which this doesnt work.
Please find the relevant script snippet. If you can help.
HTML:
<form>
<i class="fa fa-asterisk" ng-if="fadedRequestorIcon" data-placement="top" title="Required field"></i><i class="fa fa-asterisk" style="color:red" ng-if="mandatoryRequestorIcon"></i>
<label class="form-label" for="caller">Caller</label><br>
<sn-record-picker field="users" table="'sys_user'" display-field="'name'" display-fields="'user_name,email'" value-field="'sys_id'" search-fields="'name,user_name'" page-size="100"></sn-record-picker>
<div class="form-outline" >
<i class="fa fa-asterisk" ng-if="fadedRequestorIcon" data-placement="top" title="Required field"></i><i class="fa fa-asterisk" style="color:red" ng-if="mandatoryRequestorIcon"></i>
<label class="form-label" for="description">Short description</label>
<input type="text" ng-model='c.data.desc' id="description" class="form-control" ng-change="checkdescVal(c.data.desc)" required/>
</div>
<br>
<button ng-disabled="enableSubmitBtn" ng-click="createIncident(c.data.desc,users)" type="submit" class="btn btn-primary">Submit</button>
</form>
Client:
$scope.$on("field.change", function(evt, parms) {
alert("field change event"+parms.field.name);
if (parms.field.name == 'users') {
// clearData();
// scope.userVal = parms.newValue;
c.data.setUser = parms.newValue;
// alert(parms.newValue);
if (parms.newValue == "") {
$scope.fadedRequestorIcon = false;
$scope.mandatoryRequestorIcon = true;
} else {
$scope.fadedRequestorIcon = true;
$scope.mandatoryRequestorIcon = false;
}
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2022 08:18 AM
Try:
$rootScope.$on("field.change", function(evt, parms) { ... }
Note: dont forget to declare $rootScope as a parameter in client controller function in line 1.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2022 08:51 AM