validateElement() method

Validate a particular element
validateElement(field: String, element: HTMLElement): Promise
(* denotes a required parameter)
ParameterTypeDescription
field*StringThe field name
element*HTMLElementThe field element
Using the global script in the browser
const fv = FormValidation.formValidation(
document.getElementById('demoForm'),
{
...
}
);
fv
.validateElement('userName', userNameEle)
.then(function(status) {
// status can be one of the following value
// 'NotValidated': The element is not yet validated
// 'Valid': The element is valid
// 'Invalid': The element is invalid
...
});
Using the ES6 module
import { formValidation } from '/path/to/@form-validation/cjs/bundle/popular';
const fv = formValidation(
document.getElementById('demoForm'),
{
...
}
);
fv
.validateElement('userName', userNameEle)
.then(function(status) {
// status can be one of the following value
// 'NotValidated': The element is not yet validated
// 'Valid': The element is valid
// 'Invalid': The element is invalid
...
});
Using the npm package
import { formValidation } from '@form-validation/bundle/popular';
const fv = formValidation(
document.getElementById('demoForm'),
{
...
}
);
fv
.validateElement('userName', userNameEle)
.then(function(status) {
// status can be one of the following value
// 'NotValidated': The element is not yet validated
// 'Valid': The element is valid
// 'Invalid': The element is invalid
...
});