淘汰赛-验证两次显示相同的错误消息 [英] Knockout - validation showing same error message twice

查看:86
本文介绍了淘汰赛-验证两次显示相同的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using knockout validation plugin to validate a simple form field , validation is working but it is showing same error message twice below text box.

我的代码如下
JS视图模型

my code follows
JS viewmodel

    $(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>

这有什么问题吗?

推荐答案

您应将验证选项放在javascript中的html OR中.在这里,您都需要做. 我建议只将它们放到javascript上,然后从html中将其删除,如下所示:

You should put the validation options in the html OR in the javascript. Here you are doing both. I suggest putting them only to the javascript and remove them from the html like this:

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

这篇关于淘汰赛-验证两次显示相同的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆