Skip to content

Commit

Permalink
Merge pull request #82 from tb/bootstrap-form-group
Browse files Browse the repository at this point in the history
Toggle has-error on bootstrap form-group
  • Loading branch information
Huei Tan committed Mar 9, 2015
2 parents 7fdffea + bd8e73f commit 6b22fe2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ $validationProvider.setErrorHTML(function (msg) {

You can add the bootstrap class `.has-success` in a similar fashion.

To toggle `.has-error` class on bootstrap `.form-group` wrapper for labels and controls, add:

```javascript
angular.extend($validationProvider, {
validCallback: function (element){
$(element).parents('.form-group:first').removeClass('has-error');
},
invalidCallback: function (element) {
$(element).parents('.form-group:first').addClass('has-error');
}
});
```

CHANGELOG
=====
See [release](https://github.com/huei90/angular-validation/releases)
Expand Down
15 changes: 15 additions & 0 deletions dist/angular-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@
return deferred.promise;
};

/**
* Do this function if validation valid
* @param element
*/
this.validCallback = null;

/**
* Do this function if validation invalid
* @param element
*/
this.invalidCallback = null;

/**
* reset the specific form
Expand Down Expand Up @@ -269,6 +280,8 @@
showErrorMessage: this.showErrorMessage,
checkValid: this.checkValid,
validate: this.validate,
validCallback: this.validCallback,
invalidCallback: this.invalidCallback,
reset: this.reset
};
}
Expand Down Expand Up @@ -312,6 +325,7 @@
}
ctrl.$setValidity(ctrl.$name, true);
if (scope.validCallback) scope.validCallback();
if ($validationProvider.validCallback) $validationProvider.validCallback(element);

return true;
};
Expand Down Expand Up @@ -343,6 +357,7 @@
}
ctrl.$setValidity(ctrl.$name, false);
if (scope.inValidCallback) scope.inValidCallback();
if ($validationProvider.invalidCallback) $validationProvider.invalidCallback(element);

return false;
};
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.

2 changes: 2 additions & 0 deletions src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
}
ctrl.$setValidity(ctrl.$name, true);
if (scope.validCallback) scope.validCallback();
if ($validationProvider.validCallback) $validationProvider.validCallback(element);

return true;
};
Expand Down Expand Up @@ -64,6 +65,7 @@
}
ctrl.$setValidity(ctrl.$name, false);
if (scope.inValidCallback) scope.inValidCallback();
if ($validationProvider.invalidCallback) $validationProvider.invalidCallback(element);

return false;
};
Expand Down
13 changes: 13 additions & 0 deletions src/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@
return deferred.promise;
};

/**
* Do this function if validation valid
* @param element
*/
this.validCallback = null;

/**
* Do this function if validation invalid
* @param element
*/
this.invalidCallback = null;

/**
* reset the specific form
Expand Down Expand Up @@ -265,6 +276,8 @@
showErrorMessage: this.showErrorMessage,
checkValid: this.checkValid,
validate: this.validate,
validCallback: this.validCallback,
invalidCallback: this.invalidCallback,
reset: this.reset
};
}
Expand Down

0 comments on commit 6b22fe2

Please sign in to comment.