...
Status of project: (in development)
bower install ui-form-validation
- Include script location inside HTML:
<script src="bower_components/ui-form-validation/dist/scripts/uiFormValidation.min.js"></script>
- Add the
uiFormValidation
module in your application:
angular.module("myModule", ["uiFormValidation"]);
Library package contains some demos located on examples
.
List of demos:
index.html
-- Simple form validation with the custom validation with corresponding validation message (Bootstrap)
validation-errors.html
-- Examples how to insert validation errors messages into pages using various locations
app.config(function(uiFormValidationProvider) {
uiFormValidationProvider.addFormValidation(
{
validationName: "agreementChecked",
validate: function (value) {
return value;
}
});
});
// * matches all form controller names, it can be replaced for the specific one
{
"*": {
"agreementChecked": "You have to agree with terms."
}
}
// First way
app.config(function(uiFormValidationProvider) {
uiFormValidationProvider.addValidationErrorMessages("default", "custom.messages");
});
//Second way
app.run(function(validationErrorMessagesService) {
var validationErrorMessages = {'*' : {notTheSame: "Passwords are not the same."}};
validationErrorMessagesService.addValidationErrorMessages("default", "custom/namespace/default.messages", validationErrorMessages);
});
// Definition of the detault one
app.config(function(uiFormValidationProvider) {
uiFormValidationProvider.validationErrorsTemplate = "path/to/template.html";
});
// Per one control
<input ng-model="agreeWith" name="agreeWith" validation-errors-template="path/to/template.html" type="checkbox">
// Per whole form
<form class="form-horizontal" name="libAngularForm" validation-errors-template="path/to/template.html" ui-validation>
// Using after - after{this} is default mode
<input ng-model="agreeWith" name="agreeWith" validation-errors-location="after{this}" type="checkbox">
<input ng-model="agreeWith" name="agreeWith" validation-errors-location="after{parent().parent()}" type="checkbox">
// Using append
<input ng-model="agreeWith" name="agreeWith" validation-errors-location="append{this}" type="checkbox">
<input ng-model="agreeWith" name="agreeWith" validation-errors-location="append{parent().parent()}" type="checkbox">
// Using explicit - does not insert anything
<input ng-model="agreeWith" name="agreeWith" validation-errors-location="explicit" type="checkbox">
// Per whole form
<form class="form-horizontal" name="libAngularForm" validation-errors-location="explicit" ui-validation>
<div class="col-md-10" validation-errors="name3 date3" validation-controller="libAngularForm">
<input ng-model="agreeWith" name="agreeWith" validation-errors-mode="onInvalid" type="checkbox">
<input ng-model="agreeWith" name="agreeWith" validation-errors-mode="onSubmitAndInvalid" type="checkbox">
<input ng-model="agreeWith" name="agreeWith" validation-errors-mode="onDirtyAndInvalid" type="checkbox">
// Per whole form
<form class="form-horizontal" name="libAngularForm" validation-errors-mode="onInvalid" ui-validation>
<h5 validation-notice-mode="onInvalid" validation-notice="controlName">colored</h5>
<h5 validation-notice-mode="onInvalid" validation-notice="onSubmitAndInvalid">colored</h5>
<h5 validation-notice-mode="onInvalid" validation-notice="onDirtyAndInvalid">colored</h5>
// Per whole form
<form class="form-horizontal" name="libAngularForm" validation-notice-mode="onInvalid" ui-validation>
Author: Radim Loskot
gmail.com: radim.loskot (e-mail)