<
form
id
=
"
demoForm
"
>
<
input
type
=
"
hidden
"
name
=
"
dest
"
/>
<
div
id
=
"
destination
"
>
div
>
...
form
>
const
demoForm
=
document
.
getElementById
(
'demoForm'
)
;
const
fv
=
FormValidation
.
formValidation
(
demoForm
,
{
fields
:
{
dest
:
{
validators
:
{
notEmpty
:
{
message
:
'Please choose one city'
}
}
}
,
}
,
plugins
:
{
...
}
,
}
)
;
destination
element above:
const
destinationEle
=
jQuery
(
'#destination'
)
.
magicSuggest
(
{
data
:
[
'Amsterdam'
,
'Barcelona'
,
'Hanoi'
,
'London'
,
'New York'
,
'Paris'
,
'Rome'
,
'San Francisco'
,
'Seoul'
,
'Tokyo'
]
,
maxSelection
:
1
,
}
)
;
selectionchange
event and the FormValidation's
revalidateField() method
. The following piece of code illustrates that approach:
jQuery
(
destinationEle
)
.
on
(
'selectionchange'
,
function
(
e
,
m
)
{
// Get the selected item
const
data
=
this
.
getSelection
(
)
;
// Update the value for hidden field
destField
.
value
=
data
.
length
==
0
?
''
:
data
[
0
]
.
name
;
// Revalidate the field
fv
.
revalidateField
(
'dest'
)
;
}
)
;