MandatoryIcon plugin

Show required icons for mandatory fields

Usage

The following piece of code is the starting point to use the MandatoryIcon plugin:
<html>
<head>
<link rel="stylesheet" href="/vendors/formvalidation/dist/css/formValidation.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/formvalidation/dist/js/FormValidation.min.js"></script>
<script src="/vendors/formvalidation/dist/js/plugins/MandatoryIcon.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function(e) {
FormValidation.formValidation(
document.getElementById('demoForm'),
{
fields: {
...
},
plugins: {
// You have to enable MandatoryIcon plugin before the Icon plugin
mandatoryIcon: new FormValidation.plugins.MandatoryIcon({
// The CSS classes (separated by a space) that present the icon
icon: '...'
}),
icon: new FormValidation.plugins.Icon({
valid: '...',
invalid: '...',
validating: '...',
}),
...
},
}
);
});
</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.
For example, to use the plugin with FontAwesome, we can set the icon option as:
mandatoryIcon: new FormValidation.plugins.MandatoryIcon({
icon: 'fa fa-asterisk',
}),
icon: new FormValidation.plugins.Icon({
valid: 'fa fa-check',
invalid: 'fa fa-times',
validating: 'fa fa-refresh',
}),

Important note

You have to register the MandatoryIcon plugin before the Icon plugin.
// Does NOT work
plugins: {
icon: new FormValidation.plugins.Icon(...),
mandatoryIcon: new FormValidation.plugins.MandatoryIcon(...),
},
// Work
plugins: {
mandatoryIcon: new FormValidation.plugins.MandatoryIcon(...),
icon: new FormValidation.plugins.Icon(...),
},

Basic example

MandatoryIcon plugin

See also

Changelog

v1.6.0
  • Fixed an issue that the plugin doesn't work with textarea element
v1.0.0
  • First release