【问题标题】:VeeValidate 3 server side validation error showing even when the field is correct即使字段正确,VeeValidate 3 服务器端验证错误也会显示
【发布时间】:2020-11-23 04:18:50
【问题描述】:

我有一个检查两件事的函数

    {
        $data = $request->validationData();
        $exist = ApplicantUser::whereEmail($data['email'])->exists()
            || School::whereQrPathPassword($data['school_code'])->doesntExist();
        return new ExistResource1(['exist' => $exist]);
    }

每个字段有 2 条消息

this.$refs.observer1.setErrors({
                email: this.multilinguals.texts['27'][this.getLang()],
                school_code: this.multilinguals.texts['43'][this.getLang()]
              })

但是当其中只有一个错误时,两个字段都显示错误。

有什么想法吗?

【问题讨论】:

    标签: jquery typescript vue.js validation vee-validate


    【解决方案1】:

    这可能是由于您使用的 or(||) 条件。您应该使用 and(&&) 确认验证仅在满足您的两个条件时运行

    【讨论】:

    • 感谢您的回复!当我使用 && 而不是 ||当仅满足其中一个条件时,它就会通过。我需要它都正确才能继续。
    • 例如,如果我在只有一个字段正确的情况下使用 &&,它会通过而不会显示任何错误。验证器正常工作。问题是因为当其中一个字段失败时,该函数同时检查 2 个字段,同时显示两个错误消息。我只想在字段实际有错误时显示错误。
    • 我以某种方式解决了它。它花了永恒。 stackoverflow.com/questions/63152104/…
    猜你喜欢
    • 2019-10-18
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 2022-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多