const fv = FormValidation.formValidation(form, {fields: {...},plugins: {trigger: new FormValidation.plugins.Trigger(),},});// Enable the Trigger pluginfv.enablePlugin('trigger');// Check if a given plugin is enabled or notfv.isPluginEnabled('trigger'); // `true`// Disable the Trigger pluginfv.disablePlugin('trigger');
FormValidation.formValidation(form, {fields: {...},plugins: {turnstile: new FormValidation.plugins.Turnstile({...}),},});
liveMode option. All validations are disabled until users submit the form if it is set to false:FormValidation.formValidation(document.getElementById('demoForm'),{fields: {...},plugins: {submitButton: new FormValidation.plugins.SubmitButton({liveMode: false,}),...},});
true by default.hiddenPhoneInput option of the InternationalTelephoneInput plugin supports multiple fields:FormValidation.formValidation(document.getElementById('demoForm'),{fields: {...},plugins: {internationalTelephoneInput: new FormValidation.plugins.InternationalTelephoneInput({field: 'phone1,phone2',hiddenPhoneInput: 'fullPhoneNumber1,fullPhoneNumber2',}),...},});
hiddenPhoneInput option that serves the same functionality as the hiddenInput option provided by intl-tel-input.FormValidation.formValidation(document.getElementById('demoForm'),{fields: {...},plugins: {internationalTelephoneInput: new FormValidation.plugins.InternationalTelephoneInput({...hiddenPhoneInput: 'fullPhoneNumber',}),...},});
fullPhoneNumber to the form. If the corresponding input is valid, then the hidden input has the value of the full phone number. Otherwise, its value is set to empty.GET methodenabled attribute to false doesn't work with the Declarative plugin:<input type="text" name="username" data-fv-not-empty="true" data-fv-not-empty___message="The username is required" data-fv-not-empty___enabled="false" />
@form-validation/core package provides a new helper to remove undefined properties from a given object:import { utils } from '@form-validation/core';const { removeUndefined } = utils;
esm format that can be used with the <script type=module> tag:<script type="module">import { formValidation, plugins } from '/path/to/@form-validation/esm/bundle/popular.min.js';import { Bootstrap5 } from '/path/to/@form-validation/esm/plugin-bootstrap5/index.min.js';// Core plugins are already included in `bundle`const { Icon, SubmitButton, Trigger } = plugins;document.addEventListener('DOMContentLoaded', function (e) {formValidation(...,{fields: {...},plugins: {trigger: new Trigger(),bootstrap5: new Bootstrap5(),submitButton: new SubmitButton(),icon: new Icon({valid: 'fa fa-check',invalid: 'fa fa-times',validating: 'fa fa-refresh',}),},});});</script>
message property isn't definedmin or max option contains the AM/PM formatmeta property when using the AM/PM format@form-validation/plugin-j package doesn't register popular validatorsformat option contains the AM/PM formattype and extension options of the file validator are required| Package | Description |
|---|---|
@form-validation/bundle | Bundle core plugins and popular validators. See the next section for more details |
@form-validation/core | The core of the library |
@form-validation/locales | The translation packages |
@form-validation/plugin-[plugin-name] | The given plugin where [plugin-name] represents the name of the plugin |
@form-validation/styles | The CSS styles |
@form-validation/validator-[validator-name] | The given validator where [validator-name] represents the name of the validator |
validateFileName function to check if file name(s) without extension is validfile: {validateFileName: function(fileName) {// `fileName` is the file name without the extension// returns true or false},},
requireGlobalDomain option to require a global domain. The option is false by default.
For example, a@b will be an invalid email address if you set requireGlobalDomain to true.extension and file options of the file validator can contain spacesis-valid and is-invalid CSS classes from input when it is being validatedurl has a query stringBootstrap.min.js file is the plugin provided by FormValidation. It is NOT the same as the Bootstrap(.min).js file provided by the Bootstrap framework.umd and es6 packages have different folder structures.amd, cjs and umd packages now follow the same folder structure.Uikit plugin is renamed to UiKit<!-- Before v2.0.0 --><script src="/dist/js/FormValidation.min.js"></script><!-- From v2.0.0 --><script src="/@form-validation/umd/bundle/popular.min.js"></script>
| Old path | New path |
|---|---|
/formvalidation/dist/css/formValidation.css | /@form-validation/umd/styles/index.css |
/formvalidation/dist/css/formValidation.min.css | /@form-validation/umd/styles/index.min.css |
| Old path | New path |
|---|---|
/formvalidation/dist/js/FormValidation.js | /@form-validation/umd/bundle/popular.js |
/formvalidation/dist/js/FormValidation.min.js | /@form-validation/umd/bundle/popular.min.js |
/formvalidation/dist/js/FormValidation.full.js | /@form-validation/umd/bundle/full.js |
/formvalidation/dist/js/FormValidation.full.min.js | /@form-validation/umd/bundle/full.min.js |
| Old path | New path |
|---|---|
/formvalidation/dist/js/plugins/Bootstrap.js | /@form-validation/umd/plugin-bootstrap/index.js |
/formvalidation/dist/js/plugins/Bootstrap.min.js | /@form-validation/umd/plugin-bootstrap/index.min.js |
/formvalidation/dist/js/plugins/PasswordStrength.js | /@form-validation/umd/plugin-password-strength/index.js |
/formvalidation/dist/js/plugins/PasswordStrength.min.js | /@form-validation/umd/plugin-password-strength/index.min.js |
| Old path | New path |
|---|---|
/formvalidation/dist/js/validators/vat.js | /@form-validation/umd/validator-vat/index.js |
/formvalidation/dist/js/validators/vat.min.js | /@form-validation/umd/validator-vat/index.min.js |
/formvalidation/dist/js/validators/zipCode.js | /@form-validation/umd/validator-zip-code/index.js |
/formvalidation/dist/js/validators/zipCode.min.js | /@form-validation/umd/validator-zip-code/index.min.js |
| Old path | New path |
|---|---|
/formvalidation/dist/js/locales/en_US.js | /@form-validation/umd/locales/en_US.js |
/formvalidation/dist/js/locales/en_US.min.js | /@form-validation/umd/locales/en_US.min.js |
// Before v2.0.0FormValidation.plugins.Uikit();// v2.0.0FormValidation.plugins.UiKit();
core.validator.enabled and core.validator.disabled events that are triggered after a validator is enabled or disabledFormValidation.formValidation(formElement, {fields: {// ...},plugins: {// ...},}).on('core.validator.enabled', (e) => {// Triggered after a validator is enabled}).on('core.validator.disabled', (e) => {// Triggered after a validator is disabled});
e parameter contains the following properties:| Property | Type | Description |
|---|---|---|
elements | HTMLElement[] | The array of current field elements |
field | String | The field name |
formValidation | Core | The FormValidation instance |
validator? | String | The validator name |
div at the end. It might cause an issue if the form children have the flex-grow styleenableValidator and disableValidator methods don't throw exception if the fied doesn't exist or has any validatorid selectors:<form>...</form><button id="prevButton">...</button><button id="nextButton">...</button>
const fv = FormValidation.formValidation(form, {plugins: {wizard: new FormValidation.plugins.Wizard({prevButton: document.getElementById('prevButton'),nextButton: document.getElementById('nextButton'),}),},});
goToStep() methodintl-tel-input:const fv = FormValidation.formValidation(form, {fields: {phone: {validators: {notEmpty: {message: 'The phone number is required',},},},},plugins: {internationalTelephoneInput: new FormValidation.plugins.InternationalTelephoneInput({field: 'phone',...}),},});// Get the InternationalTelephoneInput plugin instanceconst internationalTelephoneInputPlugin = fv.getPlugin('internationalTelephoneInput');// Get the `intl-tel-input` instanceconst intlTelInstance = internationalTelephoneInputPlugin.getIntTelInstance('phone');// Get the phone number including the country code// See https://github.com/jackocnr/intl-tel-input#public-methodsconst phoneNumber = intlTelInstance.getNumber();
Framework pluginFormValidation.utils.fetch function doesn't generate a unique callback for cross domain request. It can leads to the issue where there are multiple remove validators are used, for example.select elementsString.prototype such as linkupdateFieldStatus(field, 'Invalid', validator) method with the validator parameter defined doesn't mark the field as invalid. Hence, the core.field.invalid event isn't triggered for that field.init option that allows to perform initialization tasks before adding fields.FormValidation.formValidation(document.getElementById('demoForm'), {fields: {// ...},plugins: {// ...},init: (instance) => {instance.on('plugins.message.placed', function (e) {// Adjust the message placement before adding fields});},});
FormValidation.formValidation().on('core.form.notvalidated', function (e) {console.log(e.formValidation);}).on('core.form.validating', function (e) {console.log(e.formValidation);}).on('core.form.valid', function (e) {console.log(e.formValidation);}).on('core.form.invalid', function (e) {console.log(e.formValidation);});
Wizard({isStepSkipped: function (skipStepProps) {// skipStepProps.currentStep: The current step// skipStepProps.numSteps: The total number of steps// skipStepProps.targetStep: The target step// Returns `true` if you want to skip the step},});
Wizard({isFieldExcluded: function(field: string, element: HTMLElement, elements: HTMLElement[])// field: The field name// element: The field element// elements: The field elements// Returns `true` if you want to exclude the field, so it won't be validated},})
ValidateFunction to ValidateFunction<ValidateOptions>Core provides new setFieldOptions method to set the options for given fieldtrim option which is false by default<form id="demoForm">...</form><!-- External button --><button type="button" id="externalButton" />
buttons option to the SubmitButton plugin.
It is a function that accepts the current form element, and returns the list of button elements.FormValidation.formValidation(document.getElementById('demoForm'),{fields: ...,plugins: new FormValidation.plugins.SubmitButton({buttons: function(form) {return [].slice.call(document.getElementById('externalButton'));},}),});
buttons option will query all submit buttons (type="submit") inside the form.selector option is removed.data-fv-between___inclusive="false" to inclusive: 'false', not inclusive: false.selector option of the SubmitButton plugin is removed.selector of SubmitButton plugin, then you need to replace it with the buttons option.const strongPassword = function() {return {validate: function(input) {const value = input.value;if (value === '') {return {valid: true,};}if (value.length < 8) {return {valid: false,message: {en_US: 'The password must have at least 8 characters',vi_VN: 'Mật khẩu phải có ít nhất 8 ký tự',},};}...}};};
normalizeResult method which can cause an exceptiongetStatues() method of FieldStatus plugin is renamed to getStatuses()getStatues of FieldStatus plugin, then you need to change to getStatuses.const demoForm = document.getElementById('demoForm');// Submit buttonconst submitButton = demoForm.querySelector('[name="signup"]');const fv = FormValidation.formValidation(demoForm, {fields: {...},plugins: {fieldStatus: new FormValidation.plugins.FieldStatus({onStatusChanged: function(areFieldsValid) {// areFieldsValid is true if all fields are validareFieldsValid// Enable the submit button// so user has a chance to submit the form again? submitButton.removeAttribute('disabled')// Disable the submit button: submitButton.setAttribute('disabled', 'disabled');}}),...}});
aspNetButton option provided by the SubmitButton plugin:<form id="demoForm" runat="server"><asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_OnClick" /></form><script>document.addEventListener('DOMContentLoaded', function(e) {const demoForm = document.getElementById('demoForm');const fv = FormValidation.formValidation(demoForm, {fields: {...},plugins: {submitButton: new FormValidation.plugins.SubmitButton({aspNetButton: true,}),}});});</script>
Status from this version, so please replace Status with the corresponding value. For example:
FormValidation.Status.Validating must be replaced with string of 'Validating'.Status with corresponding value:| Replace | With |
|---|---|
FormValidation.Status.Ignored | 'Ignored' |
FormValidation.Status.Invalid | 'Invalid' |
FormValidation.Status.NotValidated | 'NotValidated' |
FormValidation.Status.Valid | 'Valid' |
FormValidation.Status.Validating | 'Validating' |
<script src="/vendors/@form-validation/umd/bundle/popular.min.js"></script><script src="/vendors/@form-validation/umd/plugin-auto-focus/index.min.js"></script>
<formid="demoForm"method="POST"data-fvp-trigger="true"data-fvp-trigger___class="FormValidation.plugins.Trigger"data-fvp-tachyons="true"data-fvp-tachyons___class="FormValidation.plugins.Tachyons"data-fvp-submit-button="true"data-fvp-submit-button___class="FormValidation.plugins.SubmitButton"data-fvp-icon="true"data-fvp-icon___class="FormValidation.plugins.Icon"data-fvp-icon___valid="fa fa-check"data-fvp-icon___invalid="fa fa-times"data-fvp-icon___validating="fa fa-refresh">...</form><script>document.addEventListener('DOMContentLoaded', function (e) {const form = document.getElementById('demoForm');FormValidation.formValidation(form, {plugins: {// You have to register the Declarative plugin onlydeclarative: new FormValidation.plugins.Declarative(),},});});</script>
<form id="demoForm">...</form><script>document.addEventListener('DOMContentLoaded', function (e) {const form = document.getElementById('demoForm');FormValidation.formValidation(form, {plugins: {declarative: new FormValidation.plugins.Declarative(),// Other pluginstrigger: new FormValidation.plugins.Trigger(),tachyons: new FormValidation.plugins.Tachyons(),submitButton: new FormValidation.plugins.SubmitButton(),icon: new FormValidation.plugins.Icon({valid: 'fa fa-check',invalid: 'fa fa-times',validating: 'fa fa-refresh',}),},});});</script>
id package to save imports when using with ES6 module.id package if you only want to validate the identification number of particular country:// You might need to change the importing pathimport id from '/vendors/@form-validation/cjs/validator-id';const result = id().validate({value: ...,options: {country: 'BR',message: 'The input is not a valid Brazilian identification number',},});
// You might need to change the importing pathimport brId from '/vendors/@form-validation/cjs/validator-id/brId';const result = brId().validate('An ID here');
vat package to save imports when using with ES6 module.excluded option in v0.8.1 and earlier versions.onPrefocus option in the AutoFocus plugin. This option is useful when you want to activate the tab containing the first invalid field.| Plugin | Supported CSS framework |
|---|---|
| Materialize plugin | MaterializeCSS v1.0.0-rc.2 |
| Milligram plugin | milligram v1.3.0 |
| Mini plugin | mini.css v3.0.0 |
| Mui plugin | MUI v0.9.39 |
| Turret plugin | turretcss v4.1.4 |
| Plugin | Supported CSS framework |
|---|---|
| Bootstrap plugin | Bootstrap v4.1.2 |
| Semantic plugin | Semantic UI v2.3.3 |
| Spectre plugin | Spectre v0.5.3 |
| Tachyons plugin | Tachyons v4.10.0 |
| Uikit plugin | UIKit v3.0.0-rc.8 |
delay option that supports pending validation for a given number of seconds after user stops filling in the field.min, max options in the date validator accept a function returning a Date object or a stringtimeout option in the Recaptcha plugin. The captcha expiration will be handled by the plugin automaticallystoken option in the Recaptcha pluginvalidator parameter when setting the field statusFormValidation.utils.fetch() method don't send the correct data for POST requestimport and integrate with JavaScript frameworks such as React, Vue, Sapper, etc.const result = FormValidation.validators.creditCard().validate({value: '340653705597107',options: {message: 'The credit card number is not valid',},});// result.valid === true// result.meta.type === 'AMERICAN_EXPRESS'
// You might need to change the importing pathimport creditCard from '/vendors/formvalidation/dist/js/es6/validators/creditCard';const result = creditCard().validate({value: '340653705597107',options: {message: 'The credit card number is not valid',},});// result.valid === true// result.meta.type === 'AMERICAN_EXPRESS'
| Plugin | Support CSS framework |
|---|---|
| Bootstrap plugin | Bootstrap v4.1.1 |
| Bootstrap3 plugin | Boostrap v3.3.7 |
| Bulma plugin | Bulma v0.7.1 |
| Foundation plugin | Zurb Foundation v6.4.3 |
| Pure plugin | PureCSS v1.0.0 |
| Semantic plugin | Semantic UI v2.3.1 |
| Shoelace plugin | Shoelace v1.0.0-beta24 |
| Spectre plugin | Spectre v0.5.1 |
| Tachyons plugin | Tachyons v4.9.1 |
| Uikit plugin | UIKit v3.0.0-beta.42 |
<div class="fl w-100 bl bt b--light-gray"><Framework name="Bootstrap 4" url="/guide/plugins/bootstrap/" isNew /><Framework name="Foundation" url="/guide/plugins/foundation/" /><Framework name="UIKit" url="/guide/plugins/ui-kit/" /></div><div class="fl w-100 bl b--light-gray"><Framework name="Semantic UI" url="/guide/plugins/semantic/" /><Framework name="PureCSS" url="/guide/plugins/pure/" /><Framework name="Bulma" url="/guide/plugins/bulma/" isNew /></div><div class="fl w-100 bl b--light-gray"><Framework name="Shoelace" url="/guide/plugins/shoelace/" isNew /><Framework name="Spectre" url="/guide/plugins/spectre/" isNew /><Framework name="Tachyons" url="/guide/plugins/tachyons/" isNew /></div>
include!Copy button on the top right cornerpostMessage() method. No accessing the DOM directly as in the previous version.| Options | Plugin |
|---|---|
autoFocus | AutoFocus plugin |
err: 'tooltip' | Tooltip plugin |
icon | Icon plugin |
row | Message plugin |
threshold | Trigger plugin |
trigger | Trigger plugin |
button | Removed |
excluded | Removed |
live | Removed |
message | Removed |
verbose | Removed |
framework to support form made in given CSS framework. v1.0.0 also supports native form without using any CSS framework.
Also, the framework is removed and supporting CSS frameworks are served via the following plugins:| Old framework option | Plugin |
|---|---|
framework: 'bootstrap' | Bootstrap3 plugin |
framework: 'bootstrap4' | Bootstrap plugin |
framework: 'foundation' | Foundation plugin |
framework: 'foundation5' | Zurb Foundation 5 isn't supported anymore |
framework: 'pure' | Pure plugin |
framework: 'semantic' | Semantic plugin |
framework: 'uikit' | Uikit plugin |
data-fv-notempty="true" for example, to associated validator rules.
In v1.0.0, you have to enable the Declarative plugin.message option and all the error messages are taken from the English translation package by default. From this version, the core library (FormValidation(.min).js) doesn't consist
of any language package, including English package. You have to load them manually. See the Localization page for more details.| Old add-on | Plugin |
|---|---|
| i18n | L10n plugin |
| mandatoryIcon | MandatoryIcon plugin |
| reCaptcha1 | It isn't supported anymore |
| reCaptcha2 | Recaptcha plugin |
| Old API | New API |
|---|---|
addField() | addField() method |
enableFieldValidators() | disableValidator() method |
| enableValidator() method | |
getFieldElements() | getElements() method |
getOptions() | getFields() method |
removeField() | removeField() method |
resetField() | resetField() method |
resetForm() | resetForm() method |
revalidateField() | revalidateField() method |
updateOption() | updateValidatorOption() method |
updateStatus() | updateElementStatus() method |
| updateFieldStatus() method | |
validate() | validate() method |
validateField() | validateField() method |
defaultSubmit() | Removed |
disableSubmitButtons() | Removed |
getDynamicOption() | Removed |
getInvalidFields() | Removed |
getMessages() | Removed |
getSubmitButton() | Removed |
isValid() | Removed |
isValidContainer() | Removed |
isValidField() | Removed |
updateMessage() | Removed |
validateContainer() | Removed |
core.[form/field/validator].[event].
The plugin event is named as plugins.[pluginName].[event].| Old event | New event |
|---|---|
added.field.fv | core.field.added event |
err.field.fv | core.field.invalid event |
err.validator.fv | core.validator.validated event |
success.validator.fv | core.validator.validated event |
removed.field.fv | core.field.removed event |
status.field.fv | core.field.invalid event |
| core.field.valid event | |
| core.field.validating event | |
success.field.fv | core.field.valid event |
success.form.fv | core.form.valid event |
init.field.fv | Removed |
init.form.fv | Removed |
prevalidate.form.fv | Removed |
<html><head><!-- Optional: To use FontAwesome icons for icon option --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" /><!-- Required: Bootstrap CSS --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css" /><!-- Required: FormValidation CSS --><link rel="stylesheet" href="/vendors/@form-validation/umd/styles/index.min.css" /></head><body><form id="signinForm" method="POST"><div class="form-group row"><label class="col-md-3 col-form-label">Username</label><div class="col-md-5"><input type="text" class="form-control" name="username" /></div></div><div class="form-group row"><label class="col-md-3 col-form-label">Password</label><div class="col-md-5"><input type="password" class="form-control" name="password" /></div></div><div class="form-group row"><div class="col-md-9 offset-md-3"><button type="submit" class="btn btn-primary">Sign in</button></div></div></form><!-- Required: jQuery v1.9.1 or higher --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script><!-- Required: FormValidation plugin --><script src="/vendors/@form-validation/umd/bundle/popular.min.js"></script><!-- Required: The class supports validating Bootstrap form --><script src="/vendors/formvalidation/dist/js/framework/bootstrap4.min.js"></script><script>$(document).ready(function() {$('#signinForm').formValidation(// I am validating Bootstrap 4 formframework: 'bootstrap4',// Feedback iconsicon: {valid: 'fa fa-check',invalid: 'fa fa-times',validating: 'fa fa-refresh',},// List of fields and their validation rulesfields: {username: {validators: {notEmpty: {message: 'The username is required'},stringLength: {min: 6,max: 30,message: 'The username must be more than 6 and less than 30 characters long',},regexp: {regexp: /^[a-zA-Z0-9_]+$/,message: 'The username can only consist of alphabetical, number and underscore',},}},password: {validators: {notEmpty: {message: 'The password is required'},stringLength: {min: 8,message: 'The password must have at least 8 characters',},}},},);});</script></body></html>
<html><head><!-- Optional: To use FontAwesome icons for icon plugin --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" /><!-- Required: Bootstrap CSS --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css" /><!-- Required: FormValidation CSS --><link rel="stylesheet" href="/vendors/@form-validation/umd/styles/index.min.css" /></head><body><form id="loginForm" method="POST"><!-- Form markup is the same as in the previous version --></form><!-- Required: Need es6-shim to help old browsers understand ES6 --><script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.3/es6-shim.min.js"></script><!-- Required: FormValidation library --><script src="/vendors/@form-validation/umd/bundle/popular.min.js"></script><!-- Required: Plugin supports validating Bootstrap form --><script src="/vendors/@form-validation/umd/plugin-bootstrap/index.min.js"></script><script>document.addEventListener('DOMContentLoaded', function (e) {FormValidation.formValidation(document.getElementById('loginForm'), {fields: {// Same as above},plugins: {// Trigger validation when the field value is changedtrigger: new FormValidation.plugins.Trigger(),// Support Bootstrap formbootstrap: new FormValidation.plugins.Bootstrap(),// Automatically validate the form when pressing its Submit buttonsubmitButton: new FormValidation.plugins.SubmitButton(),// Submit the form if all fields are valid after validatingdefaultSubmit: new FormValidation.plugins.DefaultSubmit(),// Display various icons based on the field validityicon: new FormValidation.plugins.Icon({valid: 'fa fa-check',invalid: 'fa fa-times',validating: 'fa fa-refresh',}),},});});</script></body></html>
framework option in previous version:| Old framework option (v0.8.1) | Plugin (v1.0.0) |
|---|---|
framework: 'bootstrap' | Bootstrap3 plugin |
framework: 'bootstrap4' | Bootstrap plugin |
framework: 'foundation' | Foundation plugin |
framework: 'foundation5' | Zurb Foundation 5 isn't supported anymore |
framework: 'pure' | Pure plugin |
framework: 'semantic' | Semantic plugin |
framework: 'uikit' | Uikit plugin |
framework: 'bootstrap4'validator along to the status.field.fv eventformnovalidate attribute causes IE to send two postbacks to serverlive mode disabled (live: 'disabled') and form has some radios/checkboxesdestroy() if a field is replaced manually<!-- Bootstrap CSS v4.0.0 alpha --><link rel="stylesheet" href="/vendor/bootstrap/css/bootstrap.min.css" /><!-- FormValidation CSS file --><link rel="stylesheet" href="/vendor/formvalidation/dist/css/formValidation.min.css" /><!-- jQuery v1.9.1 or higher --><script src="/vendor/jquery/jquery.min.js"></script><!-- Tether library, which is required if you want to use Bootstrap tooltip --><script src="/vendor/tether/js/tether.min.js"></script><!-- Bootstrap JS --><script src="/vendor/bootstrap/js/bootstrap.min.js"></script><!-- FormValidation plugin and the class supports validating Bootstrap form --><script src="/vendor/formvalidation/dist/js/formValidation.min.js"></script><script src="/vendor/formvalidation/dist/js/framework/bootstrap4.min.js"></script>
bootstrap(.min).js file provided by the Bootstrap framework with bootstrap4(.min).js provided by FormValidation which is placed inside the formvalidation/dist/js/framework directory.<!-- Foundation v5 CSS --><link rel="stylesheet" href="/vendor/foundation/css/normalize.min.css" /><link rel="stylesheet" href="/vendor/foundation/css/foundation.min.css" /><!-- FormValidation CSS file --><link rel="stylesheet" href="/vendor/formvalidation/dist/css/formValidation.min.css" /><!-- jQuery v1.9.1 or higher --><script src="/vendor/jquery/jquery.min.js"></script><!-- Foundation JS file --><script src="/vendor/foundation/js/vendor/modernizr.js"></script><script src="/vendor/foundation/js/foundation/foundation.js"></script><script src="/vendor/foundation/js/foundation/foundation.tooltip.js"></script><!-- FormValidation plugin and the class supports validating Foundation form --><script src="/vendor/formvalidation/dist/js/formValidation.min.js"></script><script src="/vendor/formvalidation/dist/js/framework/foundation5.min.js"></script>
foundation(.min).js file provided by the Foundation framework with foundation5(.min).js provided by FormValidation which is placed inside the formvalidation/dist/js/framework directory.framework option as following:// If your form uses Bootstrap 4 alpha$(yourForm).formValidation({framework: 'bootstrap4',...});// If your form uses Foundation 5$(yourForm).formValidation({framework: 'foundation5',...});
priority option that allows to set the validator execution orderrst.field.fv and rst.form.fv events that are triggered after calling resetField() and resetForm() methods, respectivelyflags option to use in declarative modeasync optionfields option provided by the different validator can be separated by a comma with or without a spacemin, max options follows the same format as formatupdateMessage() method doesn't work properly if the selector contains multiple class names$(form).formValidation({framework: '...',fields: {username: {validators: {required: {alias: 'notEmpty',message: 'The username is required',},},},},});
$(form).formValidation({framework: '...',fields: {password: {validators: {checkUppercase: {alias: 'callback',message: 'The password must have at least one uppercase character',callback: function(value, validator, $field) {...}},checkLowercase: {alias: 'callback',message: 'The password must have at least one lowercase character',callback: function(value, validator, $field) {...}},checkDigits: {alias: 'callback',message: 'The password must have at least one digit',callback: function(value, validator, $field) {...}},checkSpecial: {alias: 'callback',message: 'The password must have at least one special character',callback: function(value, validator, $field) {...}}}}}});
| Old | New |
|---|---|
be_FR | fr_BE |
be_NL | nl_BE |
gr_EL | el_GR |
%s are replaced with the min, max, value options when the input isn't a numbertype to the return value. The type can be DNI, NIE or CIF.isValidContainer() method doesn't ignore field which validators are totally disabledenabled option doesn't work in declarative modemessage option for form isn't used. The plugin uses default message provided by each validator insteadprevalidate.form.fv event that is triggered before validating the form$field and value in data/url callbacksSTATUS_IGNORED status. The field will be ignored for the current validation if the validator returns nullfalse if the country is not supportedexcluded optionformnovalidate attributeupdateMessage() method must return the plugin instance for chainingresetField(true) and resetForm(true) methods, the field need be reset value before updating the statusdataType, crossDomain, validKey options for remote validator.declarative option to support big formisValid() method which should return null when there is not validated or being validated field.isValid() combined do not workerr.form.fvvalidating icon when the field is being validatedresetForm() methodtransformer option doesn't work with notEmpty validatorisValidContainer() and validateContainer() methods to support fields with the same nametransformer option, allowing to hook the value of field before validatingsetLocale() and getLocale() methods to support multiple languagesvalidateContainer() methodcomposer.json fileerr, icon, row optionserror.x.x to err.x.x to avoid window.onerror being invoked by jQueryallowEmptyProtocol option to set optional protocol in uri validatorjQuery instead of window.jQueryDate object as value for min and max optionsisValidContainer() method should return null if the container consists of at least one field which is not validated yet or being validated2014-11-1 23: as valid YYYY-MM-DD h:m datehtml5Attributes mappingvalidateContainer() to use map value instead of keyvalidating icon when the field is being validated<!-- v0.5.3 --><!-- Path to Bootstrap CSS v3.0.0 or higher --><link rel="stylesheet" href="/vendor/bootstrap/css/bootstrap.min.css" /><!-- Path to BootstrapValidator CSS --><link rel="stylesheet" href="/vendor/bootstrapvalidator/dist/css/bootstrapValidator(.min).css" /><!-- jQuery v1.9.1 or higher --><script src="/vendor/jquery/jquery.min.js"></script><!-- Path to Bootstrap JS --><script src="/vendor/bootstrap/js/bootstrap.min.js"></script><!-- Path to BootstrapValidator JS --><script src="/vendor/bootstrapvalidator/dist/js/bootstrapValidator(.min).js"></script>
<!-- Path to Bootstrap CSS v3.0.0 or higher --><link rel="stylesheet" href="/vendor/bootstrap/css/bootstrap.min.css" /><!-- FormValidation CSS file --><link rel="stylesheet" href="/vendor/formvalidation/dist/css/formValidation(.min).css" /><!-- jQuery v1.9.1 or higher --><script src="/vendor/jquery/jquery.min.js"></script><!-- Path to Bootstrap JS --><script src="/vendor/bootstrap/js/bootstrap.min.js"></script><!-- FormValidation plugin and the class supports validating Bootstrap form --><script src="/vendor/formvalidation/dist/js/formValidation(.min).js"></script><script src="/vendor/formvalidation/dist/js/framework/bootstrap(.min).js"></script>
bootstrap(.min).js file provided by the Bootstrap framework with bootstrap(.min).js provided by FormValidation which is placed inside the formvalidation/dist/js/framework directory.
They are two different files and both of them need to be included as mentioned above// v0.5.3(function($) {$.fn.bootstrapValidator.validators.yourValidatorName = {validate: function(validator, $field, options) {...}};}(window.jQuery));// v0.6.0(function($) {FormValidation.Validator.yourValidatorName = {validate: function(validator, $field, options) {// ...// The validation code is the same}};}(window.jQuery));
| v0.5.3 | v0.6.0 |
|---|---|
Use data-bv-xxx attribute | Use data-fv-xxx attribute |
| v0.5.3 | v0.6.0 |
|---|---|
container | err.container |
feedbackIcons | icon |
group | row.selector |
submitButtons | button.selector |
// v0.5.3$(form).bootstrapValidator({container: 'tooltip',feedbackIcons: {valid: '...',invalid: '...',validating: '...'},group: 'td',submitButtons: '#submitButton'});// v0.6.0$(form).formValidation({framework: 'bootstrap',err: {container: 'tooltip'}icon: {valid: '...',invalid: '...',validating: '...'},row: {selector: 'td'},button: {selector: '#submitButton'}});
| v0.5.3 | v0.6.0 |
|---|---|
container | err |
feedbackIcons | icon |
group | row |
// v0.5.3$(form).bootstrapValidator({fields: {fieldName: {container: 'tooltip',feedbackIcons: false,group: '.col-sm-3',validators: {...}}}});// v0.6.0$(form).formValidation({framework: 'bootstrap',fields: {fieldName: {err: 'tooltip',icon: false,row: '.col-sm-3',validators: {...}}}});
.bv is changed to .fverror. is changed to err. to avoid window.onerror being invoked by jQuery| v0.5.3 | v0.6.0 |
|---|---|
init.form.bv | init.form.fv |
error.form.bv | err.form.fv |
success.form.bv | success.form.fv |
added.field.bv | added.field.fv |
removed.field.bv | removed.field.fv |
init.field.bv | init.field.fv |
error.field.bv | err.field.fv |
success.field.bv | success.field.fv |
status.field.bv | status.field.fv |
error.validator.bv | err.validator.fv |
success.validator.bv | success.validator.fv |
min, max options for the date validatortrim option for the stringLength validator validatorminFiles, maxFiles, minTotalSize, maxTotalSize options for the file validatorautoFocus optiontype='color' attributedata options via HTML attributesdata-bv-validatorname="data-bv-validatorname"trigger: 'blur', container: 'tooltip'isValidField() and validateField() methods for fields without validatorserror.field.bv event isn't triggered if verbose is set to falseverbose option for field doesn't override the form levelverbose optioninit and destroy methods to validatordelay option to the remote validatorcontainer option can be defined by a callbackinput-groupminlength attributeminSize option for the file validatoremail@server is not valid email addressfields optiononclick="return false;"type="number"type option when using remote validator:$(form).bootstrapValidator({fields: {username: {message: 'The username is not valid',validators: {// The validator will create an Ajax request// sending { username: 'its value' } to the back-endremote: {message: 'The username is not available',url: '/path/to/backend/',type: 'GET', // or 'POST'},},},},});
headers option to the remote validatordemo/remote.phpdemo/remote.html and demo/message.htmldemo/date.html and demo/tab.html examplesYYYY-MM-DD when using <input type="date" /><input type="date" /><input type="number" > input allows to input non-digits characterssubmitButtons option doesn't work correctlyaddField() and removeField() methods for managing dynamic fieldscontainer option for indicating the element showing all errorsenabled option enable/disable particular validatorexcluded option to exclude particular fieldfeedbackIcons option to enabled/disable feedback icons for particular fieldsgroup optiondestroy() methodgetInvalidFields() method that returns all invalid fieldsisValidContainer() methodisValidField() methodrevalidateField() methodresetField() methodupdateMessage() methodupdateOption() method for updating the particular validator option$field instance to the callback validatorseparator option for the date validator$.fn.bootstrapValidator.helpers renames mod_11_10 to mod11And10, mod_37_36 to mod37And36submitHandler option.input-group elementdata-bv-callback-callback attributeinput-groupupdateStatus() method. The plugin now doesn't show the errors, feedback icons of given field if there are uncompleted validatorsurl and method type (GET/POST)has-error classinclusive option in the between, greaterThan and lessThan validators_isExcluded() when initializing the formfalse if the country code is not supportedthreshold option doesn't work on IE 8submitHandler option. In v0.5.0, use the success.form.bv event instead.$(form).bootstrapValidator({submitHandler: function(form, validator, submitButton) {...}});
$(form).bootstrapValidator({// Removing submitHandler option}).on('success.form.bv', function (e) {// Prevent form submissione.preventDefault();var $form = $(e.target),validator = $form.data('bootstrapValidator'),submitButton = validator.getSubmitButton();// Do whatever you want here ...});
$.fn.bootstrapValidator.helpers.date method for validating a date, re-used in date, id, vat validatorsseparator option to the numeric validatorthreshold optionsubmitButtons to [type="submit"] to support input type="submit"$.fn.bootstrapValidator.helpers.mod_11_10 method that implements modulus 11, 10 (ISO 7064) algorithm. The helper is then reused in validating German and Croatian VAT numbers$.fn.bootstrapValidator.helpers.mod_37_36 method that implements modulus 37, 36 (ISO 7064) algorithm, used in GRid validatorname attribute and selector option for fieldselect elementexcluded: ':disabled' setting does not work on IE 8excluded option+1 country code and area code for US phone numberenabled is set to falseselector optionvalidate() method from submit the form automatically. So we can call the validate() method to validate the formsetLiveMode() method to turn on/off the live validating modedata-bv-trigger attribute or the trigger option| HTML 5 attribute | Equivalent validator |
|---|---|
min="..." | greaterThan validator |
max="..." | lessThan validator |
maxlength="..." | stringLength validator |
pattern="..." | regexp validator |
required | notEmpty validator |
type="color" | color validator |
type="email" | emailAddress validator |
type="range" | between validator |
type="url" | uri validator |
disableSubmitButtons() method is now marked as a public APIupdateStatus() method now accepts the field name onlytype="hidden") and invisible elementsfields.[fieldName].message option is not used when showing the error messageform.submit() inside submitHandlercontainer option for each field to indicate where the error messages are shownselector option for each field. The field can be defined by CSS validator instead of the name attributeenabled option and enableFieldValidators() method to enable/disable all validators to given fieldbower.json filecolumns option. Now the plugin works normally no matter how many columns the form usesupdateStatus() method to make the plugin play well with anotherresetForm method now only resets fields with validator rulessubmitHandler or default submission isn't called after remote validation completesresetForm() methodDeferredsubmitHandler() parametertruesubmitHandler optionlive optioncol-xs-), small (col-sm-), medium (col-md-) elementssubmitButtons option