Reputation: 271
I have a form that collects flight information from a user. The user can enter in their departure date, departure time, and departure location along with their return date, return time, and return location. There's a simple radio button selection outside my form that allows a user to toggle between round-trip flights (default) and one-way. If the user clicks one-way, the return time and date are disabled and hidden using JQuery.
I'm using FormStrapValidaton.IO/Bootstrap Validator and I've discovered that if I enter in an invalid field for the return date, then switch the flight from round-trip to one-way the error doesn't reset and I can't submit the form. I've looked at http://formvalidation.io/examples/clearing-field-when-clicking-icon/ and clearing the field; but, can't figure out how to call this from outside the form when someone clicks the radio button. Anyone know how I can call the http://formvalidation.io/api/#reset-field function for an object outside the form (or a way to do it inside the form validation logic)?
Upvotes: 2
Views: 7123
Reputation: 2370
http://formvalidation.io/examples/modal/
$('#loginForm').formValidation('resetForm', true);
Upvotes: 0
Reputation: 1316
try this will work, you should add second parameter, its Boolean from plugin website
If true, the method resets field value to empty or remove checked/selected attribute (for radio and checkbox).
var fv = $('#formId').data('formValidation');
fv.resetField('#element', true);
Upvotes: 0
Reputation: 1015
For anyone who comes across this.
I think the key is when outside of the form functions, you have to make sure you are dealing with jQuery objects.
$('#bookingForm').data('formValidation').resetField($('#returnDate'));
Upvotes: 2