<
form
>
<
button
id
=
"
loginButton
"
type
=
"
button
"
>
Login
a
>
form
>
<
script
>
document
.
addEventListener
(
'DOMContentLoaded'
,
function
(
e
)
{
// Create a FormValidation instance
const
fv
=
FormValidation
.
formValidation
(
demoForm
,
{
fields
:
{
...
}
,
plugins
:
{
...
}
,
}
)
;
const
loginButton
=
document
.
getElementById
(
'loginButton'
)
;
loginButton
.
addEventListener
(
'click'
,
function
(
)
{
fv
.
validate
(
)
.
then
(
function
(
status
)
{
// status can be one of the following value
// 'NotValidated': The form is not yet validated
// 'Valid': The form is valid
// 'Invalid': The form is invalid
...
}
)
;
}
)
;
}
)
;
script
>
const
loginButton
=
document
.
getElementById
(
'loginButton'
)
;
// Create a FormValidation instance
const
fv
=
FormValidation
.
formValidation
(
demoForm
,
{
fields
:
{
...
}
,
plugins
:
{
...
}
,
}
)
.
on
(
'core.form.validating'
,
function
(
)
{
loginButton
.
innerHTML
=
'Validating ...'
;
}
)
;
loginButton
.
addEventListener
(
'click'
,
function
(
)
{
fv
.
validate
(
)
.
then
(
function
(
status
)
{
// Update the login button content based on the validation status
loginButton
.
innerHTML
=
(
status
===
'Valid'
)
?
'Form is validated. Logging in ...'
:
'Please try again'
;
}
)
;
}
)
;