guards.js

View the Project on GitHub on-site/guards.js

Data Attributes

data-guarded

applicable to: form

available since: 1.3.0

Guard the form as if $.enableGuards(form) were called.


required

data-live-guarded

applicable to: form

available since: 1.3.0

Guard the form as if $.liveGuard(form) were called.


required

data-guard

applicable to: field

available since: 1.3.0

Guard the field as if $.guard(input).using(<name>) were called. Multiple guards can be specified by delimiting them with spaces. Any named guard can be specified, including custom named guards. Grouped guards are supported as of 1.4.0.


required


required and int

data-guard-<name>-<option>

applicable to: field

available since: 1.3.0

Provide options to a specific guard used on this field. The option must be an option object for it to work (for example, allow and regex wouldn't work with an array or regex object). However, as of version 1.3.1, all built in named guards that required something other than a single options object now support an object form as well.


int <= 3

data-guard-<name>-group

applicable to: field

available since: 1.4.0

Specify the space delimited list of groups that the named guard will apply to for this field. If this data attribute is missing or empty, the field will be grouped with all other fields with no group names.


same as the next field


same as the previous field



same as the next field


same as the previous field

data-guard-<name>-message

applicable to: form, field

available since: 1.3.0

Customize the error message for a certain type of guard. If provided on the parent form, the error message will be used on all fields in the form with the given guard. If provided on a field, the message will only apply to that field. Field messages will supercede form messages. This is as if $.guard(field).using(<guard>).message(<error message>) were called.


required


required


required

data-guard-<name>-target

applicable to: form, field

available since: 1.5.0

Customize the error target for a certain type of guard. If provided on the parent form, the error target will be used on all fields in the form with the given guard. If provided on a field, the target will only apply to that field. Field targets will supercede form messages. This is as if $.guard(field).using(<guard>).target(<error target>) were called.


required


required

Previous field target:


required

Form level target:

data-immediate-guard-error

applicable to: field

available since: 1.3.2

Mark a field as immediately having an error with the provided error message. This is used to indicate fields have errors as soon as the page loads (such as an error detected server-side). This will only work for fields embedded on the page at dom ready time, otherwise you should script the error with the never guard along with the triggerError function.


error on load