2.0.1 • Published 4 years ago

iptools-jquery-validator v2.0.1

Weekly downloads
2
License
GPL-3.0
Repository
github
Last release
4 years ago

iptools-jquery-validator Build Status npm version Bower version

jQuery form validation plugin.

Requirements

  • jQuery >=1.11.3 <4.0.0

Supported validation schemas

SchemaDescription
requiredChecks if field has value.
emailChecks if field value is email.
regexpChecks field value against regular expression defined in data-validation-regexp.
phoneChecks if field value is phone number. Allows +, space and numbers.
numericChecks if field value is numeric. Allows decimals, signs, and scientific notation.
numberChecks if field value is number.
nameChecks if field value is name, i.e. first or last name of person.
streetChecks if field value is street name.
housenumberChecks if field value is house number.
postcodeChecks if field value is post code.
matchChecks if field value matches to field referenced by data-validation-connected-field.
uniqueChecks if field value is unique in amongst given references by data-validation-unique-with and data-validation-unique-set.

Usage

iptools-jquery-validator relies on namespaced data attributes such as

AttributeDescription
data-validationComma-separated list of validation schemas to apply, e.g. data-validation="required,phone". See Supported validation schemas. 
data-validation-triggerEvent on which validation should be triggered. Only events emitted from actual control are considered.
data-validation-regexpRegular expression definition for fields with regexp validation schema.
data-validation-connected-fieldName of the connected field for fields with match validation schema.
data-validation-unique-setNamespace within which to perform unique validation.
data-validation-unique-withID of field, value of which, in combination with current field's value, makes up unique value to be validated, e.g. forename + surname.
data-validation-errormsg-<schema>Error message to be displayed in case validation fails, e.g. data-validation-errormsg-required="Name is required.". See Supported validation schemas.

Options

Following options (optional) can be used to initialise component:

OptionDescriptionDefault 
stopOnRequiredStop further validation if required validation schema failsfalse
validateOnSubmitTrigger validation on submittrue
validateOnCustomEventTrigger validation on custom eventnull
errorPublishingModePosition of error message relative to erroneous field. Possible values: insertInto, insertAfter, insertBefore, appendToParent, prependToParentappendToParent
errorMsgBoxIDHTML Element ID holding error messages. Corresponds to errorPublishingMode: 'insertInto'null
errorClassCSS class added to erroneous fields, error message and error class subscriberserror
boxAnimationModeAnimation strategy applied to errors. Possible values: default, fade, slidedefault (show/hide)
animationDurationDuration of boc animation in ms500
wipeTargetsThird party elements (e.g. errors) to be removed from DOM on validationnull

Events

Following events are dispatched on element that component was initialised on:

EventDescription
success.iptValidatorDispatched on validation success 
failure.iptValidatorDispatched on validation failure 

Example

<form method="post" action="">
  <input type="text" data-validation="required,email" data-validation-trigger="change" data-validation-errormsg-required="Dieses Feld ist ein Pflichtfeld." data-validation-errormsg-email="Bitte geben Sie eine gültige E-Mail-Adresse an.">
</form>

<script src="src/iptools-jquery-validator.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    $('form').iptValidator({
      validateOnSubmit: true,
      stopOnRequired: false,
      errorPublishingMode: 'insertAfter',
      errorMsgBoxID: null,
      errorClass: 'error'
    });
  });
</script>

Contributions

See CONTRIBUTING.md.

Licence

Copyright © 2016, 2017 Interactive Pioneers GmbH. Licenced under GPL-3.