just-validate-plugin-date
Version:
Date plugin for JustValidate
76 lines (54 loc) • 2.34 kB
Markdown
# JustValidate plugin date
[](https://codecov.io/gh/horprogs/just-validate-plugin-date)
<a href="https://bundlephobia.com/result?p=just-validate-plugin-date@latest" target="\_parent">
<img alt="" src="https://badgen.net/bundlephobia/minzip/just-validate-plugin-date@latest" />
</a>
[](https://www.codacy.com/gh/horprogs/just-validate-plugin-date/dashboard?utm_source=github.com&utm_medium=referral&utm_content=horprogs/just-validate-plugin-date&utm_campaign=Badge_Grade)
[](https://snyk.io/test/github/horprogs/Just-validate-plugin-date)
[](https://github.com/horprogs/Just-validate-plugin-date/actions)
Date validation plugin for JustValidate library
## Installation
### npm
```shell
npm install just-validate-plugin-date --save
```
### yarn
```shell
yarn add just-validate-plugin-date
```
And then use it as an imported module:
```js
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`:
```html
<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
```js
JustValidatePluginDate((fields) => ({
required: true,
format: 'dd/MM/yyyy',
isAfter: fields['#date_after'].elem.value,
isBefore: fields['#date_before'].elem.value,
}));
```
```js
import JustValidatePluginDate from 'just-validate-plugin-date';
validator.addField('#date', [
{
plugin: JustValidatePluginDate((fields) => ({
format: 'dd/MM/yyyy',
isAfter: '',
})),
},
]);
```
## Validators
- isAfter
- isBefore
- isBeforeOrEqual
- isAfterOrEqual
- isEqual