Force Meteor Autoform to revalidate when input value is changed programmatically

StackOverflow https://stackoverflow.com/questions/23513520

  •  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

  1. The user DOESN'T select any Address and they click my form's Submit button.
  2. Autoform displays error messages for the missing required fields.
  3. The user selects an Address and I populate the <INPUT>s
  4. 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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

This way?

AutoForm.resetForm(formId)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top