enabled
option to enable (disable) validators initially
const
form
=
document
.
getElementById
(
'demoForm'
)
;
const
fv
=
FormValidation
.
formValidation
(
form
,
{
fields
:
{
yourId
:
{
validators
:
{
id
:
{
// The id validator is enabled by default
enabled
:
true
,
country
:
'BR'
,
message
:
'Please enter a valid Brazilian ID number'
,
}
,
vat
:
{
// The vat validator is disabled initially
enabled
:
false
,
country
:
'BR'
,
message
:
'Please enter a valid Brazilian VAT number'
,
}
,
}
,
}
,
}
,
}
)
;
form
.
querySelector
(
'[name="yourId"]'
)
.
addEventListener
(
'keyup'
,
function
(
e
)
{
switch
(
e
.
target
.
value
.
length
)
{
// User is trying to put a VAT number
case
14
:
fv
// Disable the id validator
.
disableValidator
(
'yourId'
,
'id'
)
// Enable the vat one
.
enableValidator
(
'yourId'
,
'vat'
)
// Revalidate field
.
revalidateField
(
'yourId'
)
;
break
;
// User is trying to put an ID number
case
11
:
default
:
fv
.
enableValidator
(
'yourId'
,
'id'
)
.
disableValidator
(
'yourId'
,
'vat'
)
.
revalidateField
(
'yourId'
)
;
break
;
}
}
)
;