Skip to content

Commit

Permalink
Allow disable showing success message #6
Browse files Browse the repository at this point in the history
  • Loading branch information
hueitan committed Apr 11, 2014
1 parent 5b207ad commit 09894d8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
32 changes: 30 additions & 2 deletions dist/angular-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,24 @@
};


/**
* Whether show the validation success message
* You can easily change this to false in your config
* example: $validationProvider.showSuccessMessage = false;
* @type {boolean}
*/
this.showSuccessMessage = true;


/**
* Whether show the validation error message
* You can easily change this to false in your config
* example: $validationProvider.showErrorMessage = false;
* @type {boolean}
*/
this.showErrorMessage = true;


/**
* Check form valid, return true
* checkValid(Form): Check the specific form(Form) valid from angular `$valid`
Expand Down Expand Up @@ -230,6 +248,8 @@
getExpression: this.getExpression,
setDefaultMsg: this.setDefaultMsg,
getDefaultMsg: this.getDefaultMsg,
showSuccessMessage: this.showSuccessMessage,
showErrorMessage: this.showErrorMessage,
checkValid: this.checkValid,
validate: this.validate,
reset: this.reset
Expand Down Expand Up @@ -257,7 +277,11 @@
* @returns {}
*/
var validFunc = function (element, validMessage, validation, callback, ctrl) {
element.next().html($validationProvider.getSuccessHTML(validMessage || $validationProvider.getDefaultMsg(validation).success));
if ($validationProvider.showSuccessMessage) {
element.next().html($validationProvider.getSuccessHTML(validMessage || $validationProvider.getDefaultMsg(validation).success));
} else {
element.next().html('');
}
ctrl.$setValidity(ctrl.$name, true);
if (callback) callback();
};
Expand All @@ -273,7 +297,11 @@
* @returns {}
*/
var invalidFunc = function (element, validMessage, validation, callback, ctrl) {
element.next().html($validationProvider.getErrorHTML(validMessage || $validationProvider.getDefaultMsg(validation).error));
if ($validationProvider.showErrorMessage) {
element.next().html($validationProvider.getErrorHTML(validMessage || $validationProvider.getDefaultMsg(validation).error));
} else {
element.next().html('');
}
ctrl.$setValidity(ctrl.$name, false);
if (callback) callback();
};
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: 10 additions & 2 deletions src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
* @returns {}
*/
var validFunc = function (element, validMessage, validation, callback, ctrl) {
element.next().html($validationProvider.getSuccessHTML(validMessage || $validationProvider.getDefaultMsg(validation).success));
if ($validationProvider.showSuccessMessage) {
element.next().html($validationProvider.getSuccessHTML(validMessage || $validationProvider.getDefaultMsg(validation).success));
} else {
element.next().html('');
}
ctrl.$setValidity(ctrl.$name, true);
if (callback) callback();
};
Expand All @@ -32,7 +36,11 @@
* @returns {}
*/
var invalidFunc = function (element, validMessage, validation, callback, ctrl) {
element.next().html($validationProvider.getErrorHTML(validMessage || $validationProvider.getDefaultMsg(validation).error));
if ($validationProvider.showErrorMessage) {
element.next().html($validationProvider.getErrorHTML(validMessage || $validationProvider.getDefaultMsg(validation).error));
} else {
element.next().html('');
}
ctrl.$setValidity(ctrl.$name, false);
if (callback) callback();
};
Expand Down
20 changes: 20 additions & 0 deletions src/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@
};


/**
* Whether show the validation success message
* You can easily change this to false in your config
* example: $validationProvider.showSuccessMessage = false;
* @type {boolean}
*/
this.showSuccessMessage = true;


/**
* Whether show the validation error message
* You can easily change this to false in your config
* example: $validationProvider.showErrorMessage = false;
* @type {boolean}
*/
this.showErrorMessage = true;


/**
* Check form valid, return true
* checkValid(Form): Check the specific form(Form) valid from angular `$valid`
Expand Down Expand Up @@ -227,6 +245,8 @@
getExpression: this.getExpression,
setDefaultMsg: this.setDefaultMsg,
getDefaultMsg: this.getDefaultMsg,
showSuccessMessage: this.showSuccessMessage,
showErrorMessage: this.showErrorMessage,
checkValid: this.checkValid,
validate: this.validate,
reset: this.reset
Expand Down

0 comments on commit 09894d8

Please sign in to comment.