angular-form-validation
This plugin can be used to show validation message.
Directives
form-validation
: This can be used with form tag. It initiates the form validations and show the validation messages on form submit if validation fails
validation-message
:This can be used to register a field with validation and validation message/code
Property Type Description field
string
name of the form field validation
string
name of validation message
string
message which needs to be on validation failure code
string
(optional)error code which will be resolved by error code provider to show message
form-error
: This can be used to show validation message, act as a placeholder in DOM, can be placed inside form or outside form.
Property | Type | Description |
---|---|---|
name |
string (optinal) |
name of the form if directive is placed outside the form tag |
Provider
errorCodeProvider
: used to configure the error code
Function | Paramter | Description |
---|---|---|
setErrorCodeUrl |
string |
url to get error code from server-side |
Usage
- HTML
<form name="testForm" form-validation class="form-horizontal" action="#" novalidate>
<form-error></form-error>
<div class="input-group form-field">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input type="email" name="email" ng-model="email" class="form-control" placeholder="Email address" required email />
<validation-message field="email" validation="required" message="Email can't be empty"></validation-message>
<validation-message field="email" validation="email" message="Invalid email"></validation-message>
</div>
<div class="input-group form-field">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input type="password" name="passkey" ng-model="passkey" class="form-control" placeholder="Password" required="true"/>
<validation-message field="passkey" validation="required" message="Password can't be empty"></validation-message>
</div>
<div class="form-group btn-container">
<div class="col-sm-12 controls">
<button class="btn btn-success" type="submit">Login</button>
</div>
</div>
</form>
- Code
angular.module('testApp',['formValidation']);
- Demo