angular-schema-form-material icon indicating copy to clipboard operation
angular-schema-form-material copied to clipboard

Error message issues - with fixes

Open brianpkelley opened this issue 9 years ago • 0 comments

Repeating this process on a required field was creating duplicated error messages:

  1. focus field
  2. fill field
  3. blur field
  4. focus field
  5. empty field
  6. 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. https://github.com/angular/angular.js/issues/7549#issuecomment-44455307


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();
        }
      });

brianpkelley avatar Aug 10 '16 18:08 brianpkelley