|
159 | 159 | $scope.isValid = true;
|
160 | 160 | $scope.dirty = false;
|
161 | 161 | $scope.validation = function (value) {
|
162 |
| - if (_.isObject($scope.config.validators)) { |
| 162 | + if (angular.isObject($scope.config.validators)) { |
163 | 163 | $scope.errors = [];
|
164 | 164 | angular.forEach($scope.config.validators, function (args, name) {
|
165 | 165 | var error = FormusValidator.validate(name, value, $scope.config, args);
|
|
169 | 169 | });
|
170 | 170 | }
|
171 | 171 | };
|
172 |
| - $scope.$on('Formus.validate', function () { |
| 172 | + $scope.$on('Formus.validate', function (e) { |
173 | 173 | if (!$scope.config.hide) {
|
174 | 174 | $scope.validation($scope.model);
|
175 | 175 | } else {
|
|
180 | 180 | });
|
181 | 181 | var init = function () {
|
182 | 182 | $scope.parentCtrl = $element.parent().controller('formus-field');
|
183 |
| - if (_.isUndefined($scope.parentCtrl)) { |
| 183 | + if (angular.isUndefined($scope.parentCtrl)) { |
184 | 184 | $scope.parentCtrl = $element.parent().controller('formus-form');
|
185 | 185 | }
|
186 | 186 | $scope.parentScope = $scope.parentCtrl.getScope();
|
|
203 | 203 | $scope.parentScope.errors = FormusHelper.setNested($scope.parentScope.errors, $scope.config.name, newValue);
|
204 | 204 | }
|
205 | 205 | });
|
206 |
| - $scope.isParent = !_.isUndefined($scope.config.fields); |
| 206 | + $scope.isParent = !angular.isUndefined($scope.config.fields); |
207 | 207 | /** Set field type 'fieldset' when it has child fields and don't set other type */
|
208 | 208 | if ($scope.isParent && _.isUndefined($scope.config.input)) {
|
209 | 209 | $scope.config.input = 'fieldset';
|
|
213 | 213 | $element: $element,
|
214 | 214 | $attr: $attr
|
215 | 215 | });
|
216 |
| - if (_.isFunction($scope.config.linker)) { |
| 216 | + if (angular.isFunction($scope.config.linker)) { |
217 | 217 | $injector.invoke($scope.config.linker, this, {
|
218 | 218 | $scope: $scope,
|
219 | 219 | $element: $element,
|
|
312 | 312 | };
|
313 | 313 | $scope.submit = function () {
|
314 | 314 | $scope.validate().then(function () {
|
315 |
| - if (typeof $scope.config.submit.handler === 'function') { |
| 315 | + if (angular.isFunction($scope.config.submit.handler)) { |
316 | 316 | $scope.config.submit.handler();
|
317 | 317 | }
|
318 | 318 | }, angular.noop);
|
|
528 | 528 | $scope.setElementTemplate = function (templateData) {
|
529 | 529 | $element.html(templateData);
|
530 | 530 | $compile($element.contents())($scope);
|
531 |
| - if (typeof $scope.afterLoadTemplate === 'function') { |
| 531 | + if (angular.isFunction($scope.afterLoadTemplate)) { |
532 | 532 | $scope.afterLoadTemplate();
|
533 | 533 | }
|
534 | 534 | };
|
|
570 | 570 | $scope.config[name] = value;
|
571 | 571 | }
|
572 | 572 | });
|
573 |
| - if ($scope.config.label && typeof $scope.config.showLabel === 'undefined') { |
| 573 | + if ($scope.config.label && angular.isUndefined($scope.config.showLabel)) { |
574 | 574 | $scope.config.showLabel = true;
|
575 | 575 | }
|
576 | 576 | };
|
|
642 | 642 | * @param templateUrl
|
643 | 643 | */
|
644 | 644 | var setTemplateUrl = function (name, templateUrl) {
|
645 |
| - if (typeof name === 'string') { |
| 645 | + if (angular.isString(name)) { |
646 | 646 | templateMap[name] = templateUrl;
|
647 | 647 | } else {
|
648 | 648 | angular.forEach(name, function (templateUrl, name) {
|
|
750 | 750 | return null;
|
751 | 751 | }
|
752 | 752 | };
|
753 |
| - var getProvider = function ($log) { |
| 753 | + var getProvider = function ($log, $injector) { |
754 | 754 | function get(name) {
|
755 | 755 | if (validators[name]) {
|
756 | 756 | return validators[name];
|
757 | 757 | }
|
758 | 758 | }
|
759 | 759 | function validate(validatorName, value, config, args) {
|
760 | 760 | if (validators[validatorName]) {
|
761 |
| - return validators[validatorName](value, config, args); |
| 761 | + return $injector.invoke(validators[validatorName], null, { |
| 762 | + value: value, |
| 763 | + config: config, |
| 764 | + args: args |
| 765 | + }); |
762 | 766 | }
|
763 | 767 | $log.warn('Don\'t find validator with name "' + validatorName + '"');
|
764 | 768 | return null;
|
|
769 | 773 | };
|
770 | 774 | };
|
771 | 775 | var set = function (name, callback) {
|
772 |
| - if (typeof callback === 'function') { |
| 776 | + if (angular.isFunction(callback)) { |
773 | 777 | validators[name] = callback;
|
774 | 778 | } else {
|
775 | 779 | $logProvider.warn('Validator must be function. Can\'t set validator with name "' + name + '"');
|
|
0 commit comments