页面更改后如何重设Meteor AutoForm?

Mak*_*sim 2 javascript meteor meteor-autoform

我的页面带有文本字段,此字段是必填字段。我单击带有空白字段=>带有红色边框的字段“提交”(因为这是必需的)。然后,我更改页面并返回=>仍然显示边框。页面更改后如何重设流星AutoForm?谢谢。

Mat*_*art 5

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

例如:

Template.myTemplate.onDestroyed(function () {
  AutoForm.resetForm("form-id");
});
Run Code Online (Sandbox Code Playgroud)

或者您可以使用路由钩子(假设您使用Iron Router):

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

Router.onStop(myResetFormFunction, {
    only: ['routeOne']
});
Run Code Online (Sandbox Code Playgroud)