Skip to content

a helper directive to add CSS classes to your markup depending on the validation state of the form and form fields

License

Notifications You must be signed in to change notification settings

mcnilz/angular-form-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Angular-form-error

Angular-form-error is a helper directive to add CSS classes to your markup depending on the validation state of the form and form fields.

    <div form-error="'email'" class="form-group">
        <label>Email address</label>
        <input name="email" ng-model="data.email" type="email" required class="form-control">
    </div>

The directive needs the input name (name=...) and will set the CSS class form-error when the field is invalid AND the field is dirty OR the form is submitted.

You can change the default behaviour by using the form-error-logic attribute.

<div form-error="'name'" form-error-logic="alternativeLogic" class="form-group">

Define the CSS class(es) and logic in your controller:

$scope.alternativeLogic = {
    'has-error': function(field, form) {
        return field.invalid && form.submitted
    }
};

About

a helper directive to add CSS classes to your markup depending on the validation state of the form and form fields

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages