Skip to content

Commit b35cbe5

Browse files
committed
Remove unnecessary wrapping with IIFE
1 parent 09aed2e commit b35cbe5

3 files changed

Lines changed: 155 additions & 161 deletions

File tree

dist/angular-validation.js

Lines changed: 77 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -534,99 +534,96 @@
534534
* Check validator
535535
*/
536536

537-
(function() {
538-
/**
539-
* Click submit form, check the validity when submit
540-
*/
541-
scope.$on(ctrl.$name + 'submit-' + uid, function(event, index) {
542-
var value = ctrl.$viewValue,
543-
isValid = false;
544-
545-
isValid = checkValidation(scope, element, attrs, ctrl, validation, value);
546-
547-
if (attrs.validMethod === 'submit') {
548-
watch(); // clear previous scope.$watch
549-
watch = scope.$watch('model', function(value, oldValue) {
550-
value = ctrl.$viewValue;
551-
552-
// don't watch when init
553-
if (value === oldValue) {
554-
return;
555-
}
537+
/**
538+
* Click submit form, check the validity when submit
539+
*/
540+
scope.$on(ctrl.$name + 'submit-' + uid, function(event, index) {
541+
var value = ctrl.$viewValue,
542+
isValid = false;
556543

557-
// scope.$watch will translate '' to undefined
558-
// undefined/null will pass the required submit /^.+/
559-
// cause some error in this validation
560-
if (value === undefined || value === null) {
561-
value = '';
562-
}
544+
isValid = checkValidation(scope, element, attrs, ctrl, validation, value);
563545

564-
isValid = checkValidation(scope, element, attrs, ctrl, validation, value);
565-
});
546+
if (attrs.validMethod === 'submit') {
547+
watch(); // clear previous scope.$watch
548+
watch = scope.$watch('model', function(value, oldValue) {
549+
value = ctrl.$viewValue;
566550

551+
// don't watch when init
552+
if (value === oldValue) {
553+
return;
567554
}
568555

569-
var setFocus = function(isValid) {
570-
if (isValid) {
571-
delete focusElements[index];
572-
} else {
573-
focusElements[index] = element[0];
556+
// scope.$watch will translate '' to undefined
557+
// undefined/null will pass the required submit /^.+/
558+
// cause some error in this validation
559+
if (value === undefined || value === null) {
560+
value = '';
561+
}
574562

575-
$timeout(function() {
576-
focusElements[Math.min.apply(null, Object.keys(focusElements))].focus();
577-
}, 0);
578-
}
579-
};
563+
isValid = checkValidation(scope, element, attrs, ctrl, validation, value);
564+
});
580565

581-
if (isValid.constructor === Object) isValid.then(setFocus);
582-
else setFocus(isValid);
583-
});
566+
}
584567

585-
/**
586-
* Validate blur method
587-
*/
588-
if (attrs.validMethod === 'blur') {
589-
element.bind('blur', function() {
590-
var value = ctrl.$viewValue;
591-
scope.$apply(function() {
592-
checkValidation(scope, element, attrs, ctrl, validation, value);
593-
});
594-
});
568+
var setFocus = function(isValid) {
569+
if (isValid) {
570+
delete focusElements[index];
571+
} else {
572+
focusElements[index] = element[0];
595573

596-
return;
597-
}
574+
$timeout(function() {
575+
focusElements[Math.min.apply(null, Object.keys(focusElements))].focus();
576+
}, 0);
577+
}
578+
};
598579

599-
/**
600-
* Validate submit & submit-only method
601-
*/
602-
if (attrs.validMethod === 'submit' || attrs.validMethod === 'submit-only') {
603-
return;
604-
}
580+
if (isValid.constructor === Object) isValid.then(setFocus);
581+
else setFocus(isValid);
582+
});
605583

606-
/**
607-
* Validate watch method
608-
* This is the default method
609-
*/
610-
scope.$watch('model', function(value) {
611-
value = ctrl.$viewValue;
612-
/**
613-
* dirty, pristine, viewValue control here
614-
*/
615-
if (ctrl.$pristine && ctrl.$viewValue) {
616-
// has value when initial
617-
ctrl.$setViewValue(ctrl.$viewValue);
618-
} else if (ctrl.$pristine) {
619-
// Don't validate form when the input is clean(pristine)
620-
if (scope.messageId)
621-
angular.element(document.querySelector('#' + scope.messageId)).html('');
622-
else
623-
element.next().html('');
624-
return;
625-
}
626-
checkValidation(scope, element, attrs, ctrl, validation, value);
584+
/**
585+
* Validate blur method
586+
*/
587+
if (attrs.validMethod === 'blur') {
588+
element.bind('blur', function() {
589+
var value = ctrl.$viewValue;
590+
scope.$apply(function() {
591+
checkValidation(scope, element, attrs, ctrl, validation, value);
627592
});
593+
});
594+
595+
return;
596+
}
597+
598+
/**
599+
* Validate submit & submit-only method
600+
*/
601+
if (attrs.validMethod === 'submit' || attrs.validMethod === 'submit-only') {
602+
return;
603+
}
628604

629-
})();
605+
/**
606+
* Validate watch method
607+
* This is the default method
608+
*/
609+
scope.$watch('model', function(value) {
610+
value = ctrl.$viewValue;
611+
/**
612+
* dirty, pristine, viewValue control here
613+
*/
614+
if (ctrl.$pristine && ctrl.$viewValue) {
615+
// has value when initial
616+
ctrl.$setViewValue(ctrl.$viewValue);
617+
} else if (ctrl.$pristine) {
618+
// Don't validate form when the input is clean(pristine)
619+
if (scope.messageId)
620+
angular.element(document.querySelector('#' + scope.messageId)).html('');
621+
else
622+
element.next().html('');
623+
return;
624+
}
625+
checkValidation(scope, element, attrs, ctrl, validation, value);
626+
});
630627

631628
$timeout(function() {
632629
/**

0 commit comments

Comments
 (0)