Skip to content

Commit

Permalink
Fix scope.$on('submit') order
Browse files Browse the repository at this point in the history
Don't watch when init
This order is better than using return;
  • Loading branch information
hueitan committed Apr 14, 2014
1 parent a08264c commit 8e594cf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
12 changes: 8 additions & 4 deletions dist/angular-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,16 @@
scope.$on(ctrl.$name + 'submit', function () {
var value = element[0].value;

if (attrs.validMethod === 'submit') {
checkValidation(scope, element, attrs, ctrl, validation, value);

if (attrs.validMethod === 'submit') {
watch(); // clear previous scope.$watch
watch = scope.$watch('model', function (value) {
watch = scope.$watch('model', function (value, oldValue) {

// don't watch when init
if (value === oldValue) {
return;
}

// scope.$watch will translate '' to undefined
// undefined/null will pass the required submit /^.+/
Expand All @@ -432,10 +438,8 @@
checkValidation(scope, element, attrs, ctrl, validation, value);
});

return;
}

checkValidation(scope, element, attrs, ctrl, validation, value);
});

/**
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-validation.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,16 @@
scope.$on(ctrl.$name + 'submit', function () {
var value = element[0].value;

if (attrs.validMethod === 'submit') {
checkValidation(scope, element, attrs, ctrl, validation, value);

if (attrs.validMethod === 'submit') {
watch(); // clear previous scope.$watch
watch = scope.$watch('model', function (value) {
watch = scope.$watch('model', function (value, oldValue) {

// don't watch when init
if (value === oldValue) {
return;
}

// scope.$watch will translate '' to undefined
// undefined/null will pass the required submit /^.+/
Expand All @@ -175,10 +181,8 @@
checkValidation(scope, element, attrs, ctrl, validation, value);
});

return;
}

checkValidation(scope, element, attrs, ctrl, validation, value);
});

/**
Expand Down

0 comments on commit 8e594cf

Please sign in to comment.