knockout-validation

knockout-validation plugin, get isValid from specific property

こ雲淡風輕ζ 提交于 2019-12-10 12:59:23
问题 Is is possible to see if just one property is valid in the knockout-validation plugin? I could not see any reference to it in the documentation, only the ability to see if the whole model is valid. For example I wish a computed observable to have a different value depending upon if another observable is valid. 回答1: I was being led down the wrong direction, as I was using async validators and over complicated my problem, I think it is as simple as: propertyName.isValid(); e.g. self.email

How to rollback knockout validation errors?

浪尽此生 提交于 2019-12-08 08:10:36
问题 I use knockout validation 2.0.3 with entity framework 6.0 and get unexpected validation errors. Here is my workflow: Step1: (works as expected) Create a new entity with an add-dialog and try to save the new entity. Validation errors are shown because some properties are missing. This is the wanted behavior. The user cancels the dialog and I call unitofwork.rollback() to undo the creation of the new entity. Step2: Open the edit dialog for an existing entity of the same type. Try to save it as

Knockout Validation: how to validate the fields on button click, not on input change

天大地大妈咪最大 提交于 2019-12-06 23:47:33
问题 I'm using the following knockout validation plugin: https://github.com/Knockout-Contrib/Knockout-Validation I want to validate my fields when I click on the "Submit" button, not everytime when I change the input's value. How can I do that? Javascript: ko.validation.init({ insertMessages:false, messagesOnModified:false, decorateElement: true, errorElementClass: 'wrong-field' }, true); var viewModel = { firstName: ko.observable().extend({minLength: 2, maxLength: 10}), lastName: ko.observable()

Clear error on Knockout-Validation

我怕爱的太早我们不能终老 提交于 2019-12-06 17:23:50
问题 I have a page setup with Knockout.js and using Knockout-Validation. During the page load I put another plugin on a select box which fires a change, which fires the validation. I need to be able to clear that error using JS so I can start with a fresh looking UI and give feedback on the form post or select box change. I can't find anything that allows me to clear an error in Knockout-Validation. 回答1: Probably a better way that follows what is already implemented in knockout validation is to

Setting error message in html with knockout validation

房东的猫 提交于 2019-12-06 13:57:47
I would like to use knockout-validation by only adding validation rules in HTML5, which works great: http://jsfiddle.net/gt228dgm/1/ I would then like to change the default error messages generated by the browser (like "This field is required." or "Invalid"). This is pretty easily done in javascript code, But I believe this kind of texts should go into the HTML. Is that possible and how? I guess I'm looking for something like: <input data-bind='value: firstName, validate: { message: "Please enter first name" }' required pattern="^[A-Za-z]{1,255}$"/></label> I have implemented a custom knockout

Custom Knockout Validation 3 Parameters

雨燕双飞 提交于 2019-12-06 08:11:38
问题 I want to create a custom knockout validation rule that would take in the current observable's value, the value to compare it to, and a conditional. All of the examples I've seen on the web have only two parameters passed into the custom validation. I have made a workaround to pass an array with the value to compare and the conditional, but this is a bit clunky. My message format outputs the values in the array as well instead of just the otherVal . For Example: /* * Compares two values only

Clear error on Knockout-Validation

徘徊边缘 提交于 2019-12-04 22:59:21
I have a page setup with Knockout.js and using Knockout-Validation. During the page load I put another plugin on a select box which fires a change, which fires the validation. I need to be able to clear that error using JS so I can start with a fresh looking UI and give feedback on the form post or select box change. I can't find anything that allows me to clear an error in Knockout-Validation. Code Novitiate Probably a better way that follows what is already implemented in knockout validation is to say property.isModified(false); if you have a whole view model to reset simply loop through all

Conditional validation not working for anonymous Knockout validation rule

时间秒杀一切 提交于 2019-12-04 17:17:19
问题 I have following attributes in my viewmodel which use knockout validation,one of them is custom validation to check password match. model.Password = ko.observable() .extend({ required: { message: "Password is required.", params: true, onlyIf: function () { return model.IsCredentialsRequired(); }} }); model.ConfirmPassword = ko.observable(). extend({ validation: { validator: mustEqual, message: 'Passwords do not match.', params: model.Password, onlyIf: function () { return model

Custom Knockout Validation 3 Parameters

有些话、适合烂在心里 提交于 2019-12-04 13:07:13
I want to create a custom knockout validation rule that would take in the current observable's value, the value to compare it to, and a conditional. All of the examples I've seen on the web have only two parameters passed into the custom validation. I have made a workaround to pass an array with the value to compare and the conditional, but this is a bit clunky. My message format outputs the values in the array as well instead of just the otherVal . For Example: /* * Compares two values only if the specified condition is true. * Parameters: * array[0] - otherVal * array[1] - conditional * *

Knockout Validation evaluates immediately on load

给你一囗甜甜゛ 提交于 2019-12-03 18:05:48
问题 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