just-validate-plugin-date

Date plugin for JustValidate

Usage no npm install needed!

<script type="module">
  import justValidatePluginDate from 'https://cdn.skypack.dev/just-validate-plugin-date';
</script>

README

JustValidate plugin date

codecov Codacy Badge Known Vulnerabilities Release workflow

Date validation plugin for JustValidate library

Installation

npm

npm install just-validate-plugin-date --save

yarn

yarn add just-validate-plugin-date

And then use it as an imported module:

import JustValidatePluginDate from 'just-validate-plugin-date';

Or if you don't use module bundlers, just include JustValidatePluginDate script on your page from CDN and call it as window.JustValidatePluginDate:

<script src="https://unpkg.com/just-validate@latest/dist/just-validate-plugin-date.production.min.js"></script>

Usage

This plugin is supposed to use together with JustValidate library. It takes 1 argument: function which returns the validation config.

Check more details and examples here: https://github.com/horprogs/Just-validate

JustValidatePluginDate((fields) => ({
  required: true,
  format: 'dd/MM/yyyy',
  isAfter: fields['#date_after'].elem.value,
  isBefore: fields['#date_before'].elem.value,
}));
import JustValidatePluginDate from 'just-validate-plugin-date';

validator.addField('#date', [
  {
    plugin: JustValidatePluginDate((fields) => ({
      format: 'dd/MM/yyyy',
      isAfter: '',
    })),
  },
]);