Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Commit

Permalink
always run validation when field is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Feb 16, 2014
1 parent 9fcf1ac commit 33438a5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
3 changes: 2 additions & 1 deletion angular-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
if(elmTagName === "SELECT") {
if(isFieldRequired && (value === "" || typeof value === "undefined")) {
// if select option is null or empty string we already know it's invalid
// but we'll still run validation() to display proper error message
ctrl.$setValidity('validation', validate(value));
elm.unbind('blur');
return value;
Expand All @@ -364,7 +365,7 @@

// in case the field is already pre-filled
// we need to validate it without looking at the event binding
if(ctrl.$pristine && value !== "" && typeof value !== "undefined") {
if(value !== "" && typeof value !== "undefined") {
var isValid = validate(value);
ctrl.$setValidity('validation', isValid);
}
Expand Down
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ <h3 class="text-info">{{'CHANGE_LANGUAGE' | translate}}</h3>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular-route.js"></script>

<!-- angular-translate -->
<!-- DO NOT USE THESE links on live server - REPLACE WITH real code -->
<!-- Visit Angular-Translate https://github.com/PascalPrecht/angular-translate -->
<script src="lib/angular-translate/angular-translate.min.js"></script>
<script src="lib/angular-translate/angular-translate-loader-static-files.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion templates/testingForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<fieldset>
<div class="form-group">
<label for="input1">{{ 'INPUT1' | translate }}</label>
<input type="text" class="form-control" name="input1" placeholder="alpha_spaces|exact_len:3" ng-model="form1.input1" validation="alpha_spaces|exact_len:3|required" ng-init="form1.input1='abc'" validation-event="blur" />
<input type="text" class="form-control" name="input1" placeholder="alpha_spaces|exact_len:3" ng-model="form1.input1" validation="alpha_spaces|exact_len:3|required" validation-event="blur" />
<span class="validation text-danger"></span>
</div>
<div class="form-group">
Expand Down

0 comments on commit 33438a5

Please sign in to comment.