The quick solution would be to trigger the change event after changing the value of the input. .val("").trigger("change")
. This is good practise anyways, as other scripts won't notice the change otherwise too.
Force Meteor Autoform to revalidate when input value is changed programmatically
-
16-07-2023 - |
سؤال
I'm using Meteor Autoform.
Demo site, liable to disappear at any time: http://exmp-eat-46040.euw1.nitrousbox.com/form
I have a Postcode/Address Form with a <SELECT>
giving street addresses that the user can select.
I have other <INPUT>
s for House Number, Street Name, City etc.
When the user selects their address from the <SELECT>
I use jQuery to poke the address details into the various <INPUT>
s
When the user doesn't select an address I clear down all the inputs:
Template.addressSelect.events({
'change #addressSelect': function(e) {
if ($(e.target).val()=='none') {
// no address slected, clear the other fields
$('input[name="curflat_name"]').val('');
$('input[name="curhouse_name"]').val('');
$('input[name="curhouse_no"]').val('');
$('input[name="curstreet_name"]').val('');
$('input[name="curcounty"]').val('');
$('input[name="curtown"]').val('');
$('input[name="curcity"]').val('');
}
} // change #addressSelect
});
Scenario
- The user DOESN'T select any Address and they click my form's Submit button.
- Autoform displays error messages for the missing required fields.
- The user selects an Address and I populate the
<INPUT>
s - The error messages are still shown
Question
How do I clear down any Autoform generated Validation Errors? Or how do I trigger Autoform to run it's form validation after I have poked good data into the form fields?
المحلول
نصائح أخرى
This way?
AutoForm.resetForm(formId)
لا تنتمي إلى StackOverflow