简体   繁体   中英

How to reset Meteor AutoForm when page changed?

I have page with text fields, this fields are required. I click 'submit' with empty fields => fields with red border (because it is required). Then I change page and return back => borders are still shown. How to reset meteor AutoForm when page changed? Thanks.

If you want to clear existing validation errors, you need to call AutoForm.resetForm("form-id"); . You could put this call inside the Template.myTemplate.onDestroyed function, which will be triggered when the template is removed from the DOM and destroyed, ie on route change.

For instance:

Template.myTemplate.onDestroyed(function () {
  AutoForm.resetForm("form-id");
});

Or you could use routing hooks (assuming you use Iron Router ):

var myResetFormFunction = function () {
    AutoForm.resetForm("form-id");
};

Router.onStop(myResetFormFunction, {
    only: ['routeOne']
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM