Giter Club home page Giter Club logo

angularjs-validation-repeat-field's Introduction

Build Status

Synopsis:

Two way matching repeat field for HTML forms. You can use that directive for repeat password or repeat email address scenarios for your HTML form.

Installation:

First you have to install the module as a dependancy to your project:

$ bower install angularjs-validation-repeat-field --save

Then you have to add it to your scripts:

<script type="text/javascript" src="bower_components/angularjs-validation-repeat-field.js"></script>

And you have to add the module to your module dependancies:

angular.module('MyApp', ['ValidationRepeatField']);

Usage:

You have to teach two html input fields to know each other by telling them which role they are playing - master or slave. Add master for password and slave for repeat password.

Attributes you have to specify:

  • ng-model
  • validate-repeat-field
  • role
  • name
<form name="form">
  <!-- master field -->
  <label for="email">Email:</label>
  <input
    <!-- You have to specify your input name -->
    <!-- Keep the user's input -->
    ng-model="modelData.email"
    <!-- Activate the directive and tell it which field it is related to -->
    validate-repeat-field="email_repeat"
    <!-- Which role this field is playing -->
    matching-role="master"
    <!-- This is how your field will be populated to the form object -->
    name="email"
    type="email"
    id="email"
     /><br />

  <!-- slave field -->
  <label for="email_repeat">Repeat email:</label>
  <input
    no-validate
    type="email"
    name="email_repeat"
    id="email_repeat"
    ng-model="modelData.emailRepeat"
    validate-repeat-field="email"
    matching-role="slave"/><br />
</form>

The directive expects to find form in the current scope. If you use different form name you can tell the directive which name to look for:

<form name="myForm">
  <input form="myForm"
   ...
  />
</form>

If you like to print an error message in you HTML you can use [`ngMessages`](https://github.com/angular/bower-angular-messages):
```html
<p ng-messages="form.email_repeat.$error" role="alert" style="color:red">
  <!-- Replace equalFieldValue with your custom error message if such is configured -->
  <span ng-message="equalFieldValue">Your email doesn't match</span>
</p>

Configuration:

By default equalFieldValue will be set to form.$error which will set ng-invalid-equal-field-value css class name to your input field when the field values don't match. You can change that by adding the next snippet in your module.config() scope:

// require the configuration provider:
module.config(['validateRepeatFieldConfigProvider', function(validateRepeatFieldConfigProvider) {

  // set the error name you like:
  validateRepeatFieldConfigProvider.setErrorName('customErrorName');

}]);

Tests:

$ npm install
$ bower install
$ npm test

MIT License

angularjs-validation-repeat-field's People

Contributors

ibetovski avatar

Watchers

 avatar  avatar

angularjs-validation-repeat-field's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.