1.5.3 • Published 5 years ago

coriander v1.5.3

Weekly downloads
3
License
MIT
Repository
github
Last release
5 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

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.9

5 years ago

1.4.8

5 years ago

1.4.7

5 years ago

1.4.6

5 years ago

1.4.5

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.9

5 years ago

1.3.8

5 years ago

1.3.7

5 years ago

1.3.6

5 years ago

1.3.5

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.9

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.0

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago