knockout-validation

Clearing or resetting a knockout validation validatedObservable?

坚强是说给别人听的谎言 提交于 2019-12-03 17:13:22
问题 I have a view model as such: var prop1 = ko.observable().extend{ required: true }, prop2 = ko.observable().extend{ required: true }; var validation = ko.validatedObservable([prop1, prop2]); function resetFields() { prop1(undefined); prop2(undefined); } var vm = { prop1: prop1, prop2: prop2, validation: validation, reset: resetFields }; The properties prop1 and prop2 are being validated correctly via the validatedObservable, however when I execute resetFields, these properties then have errors

How to remove extender from an existing observable?

本小妞迷上赌 提交于 2019-12-03 09:53:26
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? 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(function (item) { return item.rule == "required"; }); } Demo JSFiddle . But the ko validation has support

KnockoutValidation and the conditional required rule

隐身守侯 提交于 2019-12-03 09:36:49
问题 I am trying to use KnockoutValidation with conditional statements. See code below: self.transactionType = ko.observable('Option1'); self.ConditionalField = ko.observable().extend({ required: true, onlyIf: self.transactionType = ="Option2" }); Unfortunately this doesn't work. I want to have ConditionalField only required if transactionType has value 'Option2' . What is the best way to use conditional validation with knockout.validation.js? 回答1: I have solved it. First of all I made the mistake

Clearing or resetting a knockout validation validatedObservable?

百般思念 提交于 2019-12-03 05:43:26
I have a view model as such: var prop1 = ko.observable().extend{ required: true }, prop2 = ko.observable().extend{ required: true }; var validation = ko.validatedObservable([prop1, prop2]); function resetFields() { prop1(undefined); prop2(undefined); } var vm = { prop1: prop1, prop2: prop2, validation: validation, reset: resetFields }; The properties prop1 and prop2 are being validated correctly via the validatedObservable, however when I execute resetFields, these properties then have errors on them since they've been modified and are required. Is there a way to reset the validated observable

KnockoutValidation and the conditional required rule

亡梦爱人 提交于 2019-12-02 22:37:10
I am trying to use KnockoutValidation with conditional statements. See code below: self.transactionType = ko.observable('Option1'); self.ConditionalField = ko.observable().extend({ required: true, onlyIf: self.transactionType = ="Option2" }); Unfortunately this doesn't work. I want to have ConditionalField only required if transactionType has value 'Option2' . What is the best way to use conditional validation with knockout.validation.js? Mounhim I have solved it. First of all I made the mistake of declaring the transactiontype after I had defined the conditionalfield . The end code that works

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

流过昼夜 提交于 2019-12-02 20:34:43
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, but agree it wasn't clear exactly what duxa was asking for. I want to bring the question more

Max value and numerical validation in KnockoutJS

孤人 提交于 2019-12-02 18:52:17
问题 How do I implement a max value validation and check if the observable's value is numerical, something like: self.MyInteger = ko.observable().extend({ numeric: 2 }) .extend({ maxValue: { params: 255, message: "MyInteger cannot be greater than 255" } }); 回答1: sounds like you might be after the knockout validation plugin. https://github.com/Knockout-Contrib/Knockout-Validation run the snippet below. entering a non digit or something more than 255 will cause the message to display. function model

Max value and numerical validation in KnockoutJS

*爱你&永不变心* 提交于 2019-12-02 07:50:25
How do I implement a max value validation and check if the observable's value is numerical, something like: self.MyInteger = ko.observable().extend({ numeric: 2 }) .extend({ maxValue: { params: 255, message: "MyInteger cannot be greater than 255" } }); sounds like you might be after the knockout validation plugin. https://github.com/Knockout-Contrib/Knockout-Validation run the snippet below. entering a non digit or something more than 255 will cause the message to display. function model() { var self = this; this.myObj = ko.observable().extend({ digit: true }).extend({ max: 255}); } var

Knockout Validation Only If a specific button is pressed

爷,独闯天下 提交于 2019-12-02 03:11:51
https://github.com/ericmbarnard/Knockout-Validation/wiki/Native-Rules I am using the knockout validation on my MCV3 page. The situation I have is that I have two buttons. one is Add To Collection, and other is Save. The Add to collection looks for following properties as they are required: FirstName: ko.observable().extend({ required: true }), LastName: ko.observable().extend({ required: true }), Title: ko.observable(), Email: ko.observable().extend({ required: true, email: true }), Date1: ko.observable(new Date()).extend({ required: true }), I have two functions defined that check if the page

Set a custom error message using the native rules of the knockout validation plugin

一笑奈何 提交于 2019-12-01 02:22:53
I am using Asp.net MVC3 and knockoutjs library. I need to do some client side validation. I am exploring the knockout validation plugin. So I declare the following ko.observable value in my js code: var numberValue = ko.observable().extend({ number: true }) This is my view part: <input data-bind = "value: numberValue " /> When the user enters some value that is not a number an error message is displayed : "Please enter a number". Can I display a different error message but still using the native rules? I do not want to write custom validation logic just for this. Any help with some working