1.5.3 • Published 7 years ago

coriander v1.5.3

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Coriander

Form validation library built with JavaScript

Version

1.5.3

Installation

npm

npm install coriander

unpkg

<script src="https://unpkg.com/coriander@1.5.3/src/coriander.js"></script>

Getting Started

Dataset Options

OptionTypeDefaultDescription
data-errorstringThis value is requiredError reporting that displays when validation fails for an input
data-regexstringundefinedValidate input against regex
data-requiredbooleanundefinedOnly validate input if this is present

Example

<input
  class="form-input"
  type="text"
  id="name"
  name="name"
  data-error="Please enter letters only"
  data-regex="[a-zA-Z]+(([\',. -][a-zA-Z ])?[a-zA-Z]*)*$"
  data-required="true"
/>

Call coriander and pass a form element as an argument

coriander(form);

Method Options

OptionTypeDefaultDescription
onChangebooleanundefinedListen for validation when a change is made to an input
onSubmitfunctionform.submit()handle what to do when validation passes

Example

const form = document.querySelector('.form');

coriander(form, {
  onChange: true,
  onSubmit(data) {
    const names = {};

    data.inputs.forEach(d => {
      if (d.type === 'radio') {
        names[d.name] = d.nextElementSibling.textContent;
      } else {
        names[d.name] = d.value;
      }
    });

    console.log(JSON.stringify(names));
  }
});

Built With

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

1.5.3

7 years ago

1.5.2

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.4.9

7 years ago

1.4.8

7 years ago

1.4.7

7 years ago

1.4.6

7 years ago

1.4.5

7 years ago

1.4.4

7 years ago

1.4.3

7 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.9

7 years ago

1.3.8

7 years ago

1.3.7

7 years ago

1.3.6

7 years ago

1.3.5

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.9

7 years ago

1.2.8

7 years ago

1.2.7

7 years ago

1.2.6

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.0

7 years ago

1.1.9

7 years ago

1.1.8

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago