Aria plugin

Add ARIA attributes based on the field validity

Usage

The list of ARIA attributes are:
  • aria-invalid, aria-describedby for field element
  • aria-hidden, role for associated error message element
The following piece of code is the starting point to use the Aria 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: {
aria: new FormValidation.plugins.Aria(),
...
},
}
);
});
</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-aria
  • Import and use the Aria plugin:
import { formValidation } from '@form-validation/bundle/popular';
import { Aria } from '@form-validation/plugin-aria';
formValidation(
document.getElementById('demoForm'),
{
fields: {
...
},
plugins: {
aria: new Aria(),
...
},
}
);

Basic example

Try to press the Add product button and inspect the field and error message elements using your browser Developer Tools to see how the ARIA attributes above are added to them.
Aria plugin

Changelog

v2.0.0
  • Add the npm package
v1.0.0
  • First release