繁体   English   中英

淘汰赛 - 验证两次显示相同的错误消息

[英]Knockout - validation showing same error message twice

我正在使用淘汰验证插件来验证一个简单的表单字段,验证正在工作,但它在文本框下方显示相同的错误消息两次。

我的代码如下
JS视图模型

    $(document).ready(function () {
   ko.validation.registerExtenders();
    ko.validation.configure({
        registerExtenders: true,
        messagesOnModified: false,
        insertMessages: false,
        parseInputAttributes: true,
        messageTemplate: null
    });
    ko.validation.init();

    var vm = new viewmodel();
    ko.applyBindings(vm, document.getElementById("div"));
});
that.formField= ko.observable(vm.formField).extend({ required:  true, minLength: 5, maxLength: 50 });


**html**

    <p>
       <label class="field-label">Who provides your service?</label>
        <input name="txtService" id="txtInsservice"  data-bind="value: formField, valueUpdate: 'keyup'" class="field-stretch" type="text" maxlength="50" /> 
            </p>

这有什么问题吗?

您应该将验证选项放在 html 或 javascript 中。 在这里你同时做。 我建议只将它们放在 javascript 中,然后像这样从 html 中删除它们:

<input name="txtService" id="txtInsservice"  data-bind="value: formField, valueUpdate: 'keyup'" class="field-stretch" type="text" /> 

问题可能是你在 js 文件下调用了 2 次

淘汰赛.validation.js

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM