knockout-validation

Knockout Validation ko.validation.group vs ko.validatedObservable

て烟熏妆下的殇ゞ 提交于 2019-11-30 08:29:44
What is the difference in ko.validation.group and ko.validatedObservable ? Are there particular situations when I should use one over the other? The ko.validation.group just gives you an (computed) observable of all the error messages in a model. It only collects error messages of direct properties of the model. The ko.validatedObservable on the other hand not only collects the error messages, but also wraps the model in an observable and adds an isValid property which indicates whether or not there are any error messages (i.e., the model was completely valid). Otherwise, they're essentially

How to validate an array?

懵懂的女人 提交于 2019-11-30 04:02:34
问题 I am trying to use knockout validation lib to validate an array of objects. It is not straightforward to me how to form a validation group for an array of observables. The only way I managed to make it work is like this (JSFIDDLE included): var Note = function () { var self = this; self.name = ko.observable().extend({ required: true }); }; var viewModel = function() { var self = this; self.notes = ko.observableArray([new Note(), new Note()]); self.validatedObservables = function() { var arr =

Knockout Mapping Validation

淺唱寂寞╮ 提交于 2019-11-30 03:12:38
I'm trying to attach validation to a mapped view. I'm using Knockout Mapping and Validation plugins. Pseudo-models: Person { int Id; string Name; Book[] Books; } Book { int Id; string Name; } Javascript: function viewModel() { var self = this; self.persons = ko.observableArray(); // persons are retrieved via AJAX... ko.mapping.fromJS(persons, {}, self.persons); } jQuery(function( $ ) { ko.applyBindings(new viewModel()); }); How can I extend persons observableArray to set validation rules and message? I need to validate both persons and books sub-array properties. I've found only examples that

Knockout validation hello world not running on jsfiddle

强颜欢笑 提交于 2019-11-29 16:11:34
I'm trying to ask a question about async knockout.js validation running on page load, and I'm attempting to reproduce the issue on jsfiddle. Thing is, I can't get the most basic example to work, despite having a more complex scenario running on my box. What's wrong with this? http://jsfiddle.net/C5rSm/4/ I have to post code: <div id="vm"> <input type="text" data-bind="value: validatableField" /> <p data-bind="validationMessage: validatableField"></p> <button data-bind="click: alertValue">value is alerted ok, but doesn't validate</button> </div> var Vm = function(){ var self = this; self

How to load knockout.validation with knockout in requirejs

大城市里の小女人 提交于 2019-11-29 14:07:11
I am going to define my model in require js and i need knockout and knockout validation plugin in my module and also jquery . define(["knockout","jquery","knockout.validation"], function (ko,$,validation) { // knockout model here with some knockout validation return function SignUpViewModel() { var self = this; self.name = ko.observable(); self.email = ko.observable().extend({ required: true }); self.password = ko.observable().extend({ required: true, minLength: 6 }); self.confirmPassword = ko.observable().extend({ mustEqual: self.password() }); self.company = ko.observable(); self

Knockout Validation ko.validation.group vs ko.validatedObservable

穿精又带淫゛_ 提交于 2019-11-29 11:57:08
问题 What is the difference in ko.validation.group and ko.validatedObservable ? Are there particular situations when I should use one over the other? 回答1: The ko.validation.group just gives you an (computed) observable of all the error messages in a model. It only collects error messages of direct properties of the model. The ko.validatedObservable on the other hand not only collects the error messages, but also wraps the model in an observable and adds an isValid property which indicates whether

Knockout Validation evaluates immediately on load

五迷三道 提交于 2019-11-29 09:09:12
I'm using MVC, Knockout, and Knockout Validation to validate my view model. I'm running into an issue where the validation for view model properties are firing immediately upon loading. In other words, "This field is required" shows up next to my inputs before a user has attempted to change their values. This problem is specifically happening with dropdown (select) controls. I'm guessing that this is a problem that I've created by somehow unintentionally changing/accessing/mutating the observable in another part of my javascript code. However, I don't know how to track this down. Is there a

Knockout Validation - How to show error messages

核能气质少年 提交于 2019-11-29 01:24:04
We're using Knockout.js and the Knockout-validation plugin. When a user returns to a page that has validation errors, we want the error messages to display. Does anyone know if it's possible to trigger knockout validation without actually changing the bound answer? CBlack The solution is to call showAllMessages. If the view model has nested observables, be sure to set ko.validation.configure to use deep grouping because the default value is false. Example: viewModel.save = function() { var result = ko.validation.group(viewModel, {deep: true}); if (!viewModel.isValid()) { alert("Please fix all

Knockout Mapping Validation

╄→尐↘猪︶ㄣ 提交于 2019-11-29 00:51:40
问题 I'm trying to attach validation to a mapped view. I'm using Knockout Mapping and Validation plugins. Pseudo-models: Person { int Id; string Name; Book[] Books; } Book { int Id; string Name; } Javascript: function viewModel() { var self = this; self.persons = ko.observableArray(); // persons are retrieved via AJAX... ko.mapping.fromJS(persons, {}, self.persons); } jQuery(function( $ ) { ko.applyBindings(new viewModel()); }); How can I extend persons observableArray to set validation rules and

Knockout validation hello world not running on jsfiddle

烂漫一生 提交于 2019-11-28 09:48:46
问题 I'm trying to ask a question about async knockout.js validation running on page load, and I'm attempting to reproduce the issue on jsfiddle. Thing is, I can't get the most basic example to work, despite having a more complex scenario running on my box. What's wrong with this? http://jsfiddle.net/C5rSm/4/ I have to post code: <div id="vm"> <input type="text" data-bind="value: validatableField" /> <p data-bind="validationMessage: validatableField"></p> <button data-bind="click: alertValue"