【问题标题】:vee-validate errors not updated when value changes on child component子组件上的值更改时未更新 vee-validate 错误
【发布时间】:2019-01-15 11:26:06
【问题描述】:

从 Kendo DropDownList 中选择值时,值会更新到模型,但错误始终存在于 vee-validate 的 errors 对象上。

只有在再次提交表单时才会删除错误。

我试图在小提琴中实现类似的情况,但小提琴显示了实际行为。小提琴上的一切都很好。

Fiddle Link

但是当我在实际项目中使用相同的情况时,错误不会重置。我需要再次提交表单以重置错误。

值已更新为模型,但错误仍然存​​在!

实际项目中使用的代码:

父组件

<template>
<div class="container-fluid">
    <form @submit.prevent="onSubmit('form-client')" data-vv-scope="form-client" autocomplete="off">

        <row-component :model="form_fields" :data-source="dataSourceArray" :scopes="'form-client'">
        </row-component>
        Selected Value: {{form_fields}}
        <br/>
        <button type="submit" class="ui submit button">Submit</button>
    </form>


</div>

</template>

<script>
import rowcomponent from "./Child";
export default {
  components: { "row-component": rowcomponent },
  methods: {
    onSubmit(scope) {
      this.$validator.validateAll(scope).then(result => {
        if (result) {
          // eslint-disable-next-line
          alert("Form Submitted!");
          return;
        }

        alert("Correct them errors!");
      });
    }
  },
  data: function() {
    return {
      form_fields: {
        type: null
      },
      dataSourceArray: [
        { text: "Small", value: "1" },
        { text: "Medium", value: "2" },
        { text: "Large", value: "3" },
        { text: "X-Large", value: "4" },
        { text: "2X-Large", value: "5" }
      ]
    };
  }
};
</script>

子组件

<template>
<div>
    <label class="control-label">Drop Down</label>
    <kendo-dropdownlist v-model='model.type' data-vv-name="Type" data-vv-as="Type" :data-source="dataSource" v-validate="'required'"
        :data-text-field="'text'" :data-value-field="'value'" :option-label='"Type"' :filter="'contains'" :index="0" :auto-bind="true"
        class="form-control" :class="{'input': true, 'is-danger': `errors.has(${scopes}.Type)` }">
    </kendo-dropdownlist>
    <span class="is-danger" v-if="`errors.has(${scopes}.Type)`">{{errors.first(`${scopes}.Type`)}}</span>
</div>
</template>

<script>
export default {
  inject: ["$validator"],
  props: {
    model: {
      type: Object,
      default: {}
    },
    dataSource: {
      type: Array,
      default: []
    },
    scopes: {
      type: String,
      default: ""
    }
  }
};
</script>

这个实现有什么问题?在这种情况下的任何帮助表示赞赏。

有任何指南或参考资料吗?

【问题讨论】:

    标签: vuejs2 vee-validate kendo-ui-vue


    【解决方案1】:

    这种情况是由于vee-validate 的旧版本造成的,我用新版本更新了我的代码,它按预期工作。

    vee-validate: 2.1.0-beta.7

    【讨论】:

      猜你喜欢
      • 2020-12-13
      • 2019-08-14
      • 2018-12-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-28
      • 2020-01-30
      • 2022-07-11
      • 2019-01-06
      相关资源
      最近更新 更多