Excluded plugin

Ignore validations on particular field

Usage

This plugin allows you to indicate fields which won't be validated. By default, the plugin will not validate the following kind of fields:
  • disabled
  • hidden
  • invisible
The following piece of code is the starting point to use the Excluded plugin:
<html>
<head>
<link rel="stylesheet" href="/vendors/@form-validation/umd/styles/index.min.css" />
</head>
<body>
<form id="demoForm" method="POST">...</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.3/es6-shim.min.js"></script>
<script src="/vendors/@form-validation/umd/bundle/popular.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function(e) {
FormValidation.formValidation(
document.getElementById('demoForm'),
{
fields: {
...
},
plugins: {
excluded: new FormValidation.plugins.Excluded({
excluded: function(field, element, elements) {
// field is the field name
// element is the field element
// elements is the list of field elements in case
// we have multiple elements with the same name
// return true if you want to exclude the field
}
}),
...
},
}
);
});
</script>
</body>
</html>
The sample code above assumes that the FormValidation files are placed inside the vendors directory. You might need to change the path depending on where you place them on the server.

Using the npm packages

If you are using a bundler such as Webpack, Rollup, Parcel or Vite, etc., to bundle your application, then it's recommended to use the FormValidation NPM packages.
  • Install the packages:
$ npm install @form-validation/bundle
$ npm install @form-validation/plugin-excluded
  • Import and use the Excluded plugin:
import { formValidation } from '@form-validation/bundle/popular';
import { Excluded } from '@form-validation/plugin-excluded';
formValidation(
document.getElementById('demoForm'),
{
fields: {
...
},
plugins: {
excluded: new Excluded({
excluded: function(field, element, elements) {
...
},
}),
...
},
}
);

Basic example

In the following form, there are two invisible fields called Job title and Department. Since they are not visible initially, they will not be validated when you click the Submit button. Clicking the More info button will turn them into visible fields, and as result, they will be required due to their validation rules.
Excluded plugin

See also

Changelog

v2.4.0
v2.0.0
  • Add the npm package
v1.3.0
  • First release. It means that the Excluded plugin requires FormValidation v1.3.0 or newer