parsley-laravel-extras

0.4.2 • Public • Published

ParsleyJS-LaraExtras

npm npm GitHub commits

These are extra parsley validation rules that translate well to laravel's own validation rules.

Be sure to take a look at the examples included in the repo.

Install

NPM

npm install parsley-laravel-extras

Next you can import or require it in your js:

require('parsley-laravel-extras')

import 'parsley-laravel-extras'

Or just include dist/laravel-parsley.js right after where you've included parsley.js.

Note Don't forget to include moment.js if you're using date validation.

Note If you'd like support for < IE9, include es5-shim.

Dates

Several date validation rules make use of a config option. This option let's you decide what formats are valid.

By default it looks for the following formats (in order):

window.Parsley.options.dateFormats = ['DD/MM/YY', 'DD/MM/YYYY', 'MM/DD/YY', 'MM/DD/YYYY', 'YY/MM/DD', 'YYYY/MM/DD'];

MomentJS does this strictly, meaning separators are also taken into account.

You can set your valid date formats the same way (this means that all parsley instances will get this assigned by default).

Or you can set it on your parsley instance:

$('form').parsley({
  dateFormats: ['DD-MM-YY', 'DD-MM-YYYY', 'MM-DD-YY', 'MM-DD-YYYY', 'YY-MM-DD', 'YYYY-MM-DD']
});

laravel-parsley.js

Here are all the included rules, written down as you'd assign them as data attributes to the input that would require them.

data-parsley-in="value,value,value,..."

The input's value should be in the provided comma separated list.

Laravel rule: in

data-parsley-not-in="value,value,value,..."

The input's value should not be in the provided comma separated list.

Laravel rule: not_in

data-parsley-different="#otherInput"

The input's value should not be the same as the specified other input element's value.

Laravel rule: between

data-parsley-between="[min,max]"

The input's value (a number) should be greater than min and smaller than max

data-parsley-size-number="size"

The input's value (a number) be the same as size.

Laravel rule: size

data-parsley-size-string="size"

The input's character count should be the same as size.

Laravel rule: size

data-parsley-date

The input's value should be a correct date string. Note that the separators don't matter.

Laravel rule: date

data-parsley-date-format="format"

The input's value should be the same format as specified. The format parameter only takes PHP date format characters link.

Laravel rule: date_format

data-parsley-before="before/date/here"

The input's value should be a date before the one specified as parameter.

Laravel rule: before

data-parsley-before-input="#other-input"

The input's value should be a date before the date from the #other-input's value

Laravel rule: before

data-parsley-after="after/date/here"

The input's value should be a date after the one specified as parameter.

Laravel rule: after

data-parsley-after-input="#other-input"

The input's value should be a date after the date from the #other-input's value

Laravel rule: after

data-parsley-disctinct

The input's values should be unique (checkboxes, radios, select multiple).

You can add the data-parsley-multiple="mymultiplelink" to the tags you want to include in the validation.

Laravel rule: distinct

data-parsley-in-array="#html-id|inputName"

The input's value should be present in one of the values of the provided element.

#html-id

When you specifiy an element starting with a hashtag we'll assume it's a text input that containts a comma separated list of values.

inputName

If you specify any other string we'll start looking for a checkbox with this string as name and snoop around its checked values.

Laravel rule: in_array

data-parsley-required-if="['#elementValueToCheck', 'value1,value2,..']"

The value is required only if another input's value matched one of its defined values.

Laravel rule: required_if

data-parsley-required-unless="['#elementValueToCheck', 'value1,value2,..']"

The value is required unless another input's value matched one of its defined values.

Laravel rule: required_unless

data-parsley-required-with="#elementToCheck,#elementToCheck,..."

The value is required if any of the inputs are present in the dom

Laravel rule: required_with

data-parsley-required-with-all="#elementToCheck,#elementToCheck,..."

The value is required if all of the specified inputs are present in the dom

Laravel rule: required_with_all

data-parsley-required-without="#elementToCheck,#elementCheck,..."

The value is required if any of the inputs are not present in the dom

Laravel rule: required_without

data-parsley-required-without-all="#elementToCheck,#elementToCheck,..."

The value is required if all of the specified inputs are not present in the dom

Laravel rule: required_without_all

Dependents (0)

Package Sidebar

Install

npm i parsley-laravel-extras

Weekly Downloads

3

Version

0.4.2

License

MIT

Last publish

Collaborators

  • happydemon