-
Notifications
You must be signed in to change notification settings - Fork 45
Open
@brianpkelley
Description
Repeating this process on a required field was creating duplicated error messages:
- focus field
- fill field
- blur field
- focus field
- empty field
- blur field
- Error message displayed.
Fixed by changing ng-if
to ng-show
on ng-messages
dummy element created by sfMessagesNodeHandler
.
I believe the behavior is documented here by the angular team. angular/angular.js#7549 (comment)
Error messages were not being removed on autocomplete fields, I'm not sure if this is better here or in the main angular-schema-form issue list, but I only noticed it on the md-autocomplete field.
Fixed by adding a method to the messages.js file for angular-schema-form and changing the ngModel watch to use it instead of update
var updateAsync = function( checkForErrors ) { $timeout( function() { update(checkForErrors); } ); };
...
var once = scope.$watch('ngModel',function(ngModel) { if (ngModel) { // We also listen to changes of the model via parsers and formatters. // This is since both the error message can change and given a pristine // option to not show errors the ngModel.$error might not have changed // but we're not pristine any more so we should change! ngModel.$parsers.push(function(val) { updateAsync(true); return val; }); ngModel.$formatters.push(function(val) { updateAsync(true); return val; }); once(); } });