UNPKG

pip-webui

Version:

HTML5 UI for LOB applications

46 lines (36 loc) 1.34 kB
/** * @file Special error handling for forms * @copyright Digital Living Software Corp. 2014-2016 */ /* global angular */ (function () { 'use strict'; var thisModule = angular.module('pipClearErrors', []); thisModule.directive('pipClearErrors', function () { return { restrict: 'A', require: ['ngModel', '^?form'], link: function ($scope, $element, $attrs, $ctrls) { var fieldController = $ctrls[0], formController = $ctrls[1]; $scope.$watch($attrs.ngModel, function (newValue) { clearFieldErrors(); clearFormErrors(); }); //------------------- function clearFieldErrors() { var errors = fieldController.$error; for (var prop in errors) { if (errors.hasOwnProperty(prop) && prop.substring(0, 6) == 'ERROR_') { fieldController.$setValidity(prop, true); } }; } function clearFormErrors() { formController.$serverError = {}; }; } }; }); })();