validation not working in knockout js

邮差的信 提交于 2019-12-12 06:59:13

问题


I am validating an input field for unique parameters for this i am using this code .

self.loanterm = ko.observable().extend({ required: true,unique: {
                collection: self.termValues,
                externalValue: ""
                } });

but when i am adding duplicate value it doesn't showing me any message. termValues is an observable array whose values i am adding like this .

self.PopulateLoans = ko.computed(function(){
    ko.utils.arrayForEach(dummyData, function(item){
        self.Terms.push(new Term(item));
        self.termValues.push(item.loanterm);
    });
});

i am using knockout validation plugin for this.

Here is js fiddle link


回答1:


You are missing to add validationElement binding on your input fields

<input type="text" class="edit" data-bind="value: loanterm, visible: $root.isItemEditing($data),validationElement:loanterm"  />
<strong class="read" data-bind="text: loanterm,  visible: !$root.isItemEditing($data)" ></strong>
<input type="text" class="edit" data-bind="value: termIdentifier, visible: $root.isItemEditing($data),validationElement:termIdentifier"  />


来源:https://stackoverflow.com/questions/25905527/validation-not-working-in-knockout-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!