【问题标题】:Vue-Formulate reset does not re-trigger validation messageVue-Formulate 重置不会重新触发验证消息
【发布时间】:2022-01-23 15:12:59
【问题描述】:

这个例子展示了一个用 vue-formulate 制作的非常小的表单:

https://codesandbox.io/s/vue-formulate-reseting-form-does-not-initiate-validation-message-again-yxruq

输入字段采用至少 4 个字符的字符串。点击提交后,表单将通过

重置
this.$formulate.reset(‘[name-of-the-form]‘)

它确实清除了表格。但验证信息不再出现。

必须做些什么来解决这个问题?或者这可能是一个错误?

【问题讨论】:

    标签: vue.js vue-formulate


    【解决方案1】:

    看起来$formulate.resetValidation() 方法有点过于激进,具体取决于分配的验证行为。您可以通过将 ref 应用于表单,然后显式迭代注册表来“撤消”此操作:

    <FormulateForm
      ...
      ref="form"
    >
    
    // in your submit handler:
    this.$refs.form.registry.map((input) => {
      input.formShouldShowErrors = true;
    })
    

    更新复制:https://codesandbox.io/s/vue-formulate-reseting-form-does-not-initiate-validation-message-again-forked-kn12h?file=/src/components/Reproduction.vue

    【讨论】:

    • 谢谢,这似乎有效! – 需要一个“return true”才能让 eslint 开心。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    • 1970-01-01
    • 2020-09-01
    • 2019-07-29
    • 2020-07-19
    • 2019-07-04
    • 1970-01-01
    相关资源
    最近更新 更多