页面更改时如何重置 Meteor AutoForm?

How to reset Meteor AutoForm when page changed?

我有包含文本字段的页面,这些字段是必需的。 我单击带有空字段的 'submit' => 带有红色边框的字段(因为它是必需的)。然后我更改页面并 return 返回 => 仍然显示边框。页面更改时如何重置 meteor AutoForm?谢谢。

如果您想清除现有的验证错误,您需要调用AutoForm.resetForm("form-id");。您可以将此调用放在 Template.myTemplate.onDestroyed 函数中,该函数将在模板从 DOM 中删除并销毁时触发,即在路由更改时触发。

例如:

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

或者您可以使用 routing hooks (assuming you use Iron Router):

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

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