knockout-validation

Validate observables within a collection using Knockout Validation

孤者浪人 提交于 2019-12-24 13:19:28
问题 I have a message field and collection of people being bound in an unordered list accompanied each with a drop down list of colors and a default selection. Validation on the message field works, erase the text and an error is displayed and the error count increases. However, when you change one of the drop down entries to "Choose.." (effectively unselecting the option), you receive a "this field is required" message correctly however the errors object does not appear to be updating. It must

Knockout Validation isValid always returns true

冷暖自知 提交于 2019-12-24 07:46:23
问题 I am new to using knockout and I am trying to get the validation plug-in to work. However, IsValid is always returning turn. I have also tried ViewModel.errors().length == 0 but it is always zero Here is the rest of my code, please help. ko.validation.configure({ registerExtenders: true, messagesOnModified: true, insertMessages: true, parseInputAttributes: true, messageTemplate: null }); function ViewModel(survey) { // Data var self = this; self.ProjectNumber = ko.observable(); self

Knockout validation error in Internet Explorer?

不问归期 提交于 2019-12-23 23:25:50
问题 In my razor view that using knockout and supposedly knockout validation I add the following line (to actually start using ko validation): <script src="@Url.Content("~/Scripts/knockout.validation.debug.js")" type="text/javascript"></script> When I run this view in Chrome validation is working perfectly. When I run this view in IE (9.0), I get pretty ugly message saying the following: 0x800a138f - Microsoft JScript runtime error: Unable to get value of the property 'rules': object is null or

Knockout Validation of two interdependent fields

和自甴很熟 提交于 2019-12-23 09:49:00
问题 Consider the following piece of code - var MyObjectModel = function(myObject){ var self = this; self.myNumber1 = ko.observable(myObject.number1).trimmed(); self.myNumber2 = ko.observable(myObject.number2).trimmed(); I would like to extend myNumber1 and myNumber2, to add knockout validations such that it throws an error if both are empty, and stays fine if either has a value. Any idea how I could go about achieving this ? 回答1: You can use an ko.computed to create a function which checks if at

KnockoutJS dynamic form validation

倾然丶 夕夏残阳落幕 提交于 2019-12-23 02:20:47
问题 I have a form that have a three field group that on a click of a "Add New" buttom other three field group will be added. That part is working great. I want to add a validation so all three fields are required in order to add a new group. For reference here is the code working: http://jsfiddle.net/5g8Xc/ var ContactsModel = function(contacts) { var self = this; self.contacts = ko.observableArray(ko.utils.arrayMap(contacts, function(contact) { return { firstName: contact.firstName, fathersLast:

Breeze.js & Knockout.js: translating breeze validation to knockout validation causes an 'Out of stack space' or 'Too much recursion'

情到浓时终转凉″ 提交于 2019-12-23 02:14:20
问题 I have a client side model generated by Breeze/OData and I used the code in this post to connect it to Knockout validation. It works great for validating individual fields through the isValid() method. However, whenever I try to use ko.validation.group against a Breeze Entity (assume that the knockout validation is configured with {deep: true} ), either calling showAllMessages , length or any other method that performs a tree traversal over the object graph, results in an infinite recursion

Knockout Validation Plugin Custom Error Message

故事扮演 提交于 2019-12-21 04:30:14
问题 Based on the following, how exactly do I setup the callback to display a custom error message instead of the default message? ko.validation.rules['exampleAsync'] = { async: true, // the flag that says "Hey I'm Async!" validator: function (val, otherVal, callBack) { // yes, you get a 'callback' /* some logic here */ // hand my result back to the callback callback( /* true or false */ ); // or if you want to specify a specific message callback( /* { isValid: true, message: "Lorem Ipsum" } */ );

How to remove extender from an existing observable?

允我心安 提交于 2019-12-21 03:18:08
问题 I am using the Knockout Validation plugin and setting an observable as required using the extender: myObservable.extend({required:true}); Is it possible for me to remove the extender after adding it? 回答1: You can remove all the validation relates properties form an observable which were added by the ko validation with calling: myObservable.extend({validatable: false}); Or if you want to only remove the required validation you can remove it from the rules collection: myObservable.rules.remove

Knockout Validation async validators: Is this a bug or am I doing something wrong?

那年仲夏 提交于 2019-12-20 09:52:18
问题 I really like how Eric Barnard's knockout validation lib integrates with observables, allows grouping, & offers custom validator pluggability (including on-the-fly validators). There are a couple of places where it could be more UX flexible/friendly, but overall it's reasonably well-documented... except, imo, when it comes to async validators. I wrestled with this for a few hours today before doing a search and landing on this. I think I have the same issues/questions as the original author,

How to tie together ko.validation errors with related viewmodel field names

馋奶兔 提交于 2019-12-19 17:37:53
问题 I'm using Knockout.Validation and I'd like to be able to display an error summary where each line displays the error message (obviously!) and also the field name on the view model related to it, e.g. Age - please enter a number Date of birth - please enter a proper date So far I've got a validatedObservable wrapping my view model, and this puts an errors array on my viewmodel automatically, containing all my errors. However I can't see any easy way to retrieve which field each error relates