How to dynamically change validators at runtime

428 views Asked by At

Let's say I have this validation in one field:

between: {
    min: 50,
    max: 500, 
    message: 'Please enter correct range'
}

I would like to update min and max at runtime. How can I do that ?

Thanks.

1

There are 1 answers

0
Arkni On BEST ANSWER

You can do that using the updateOption method.

See the following code:

$('#yourForm')
    // Update min & max options
    .formValidation('updateOption', 'yourInputName', 'between', 'min', 10)
    .formValidation('updateOption', 'yourInputName', 'between', 'max', 90)

    // Update message if you need to
    .formValidation('updateOption', 'yourInputName', 'between', 'message', 'Your new message')

    // You might need to revalidate field
    .formValidation('revalidateField', 'yourInputName');

# Working example:

# Refferences: