knockout-validation

Setting error message in html with knockout validation

♀尐吖头ヾ 提交于 2020-01-13 20:32:31
问题 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

Validate javascript inside attributes

自古美人都是妖i 提交于 2020-01-07 09:06:22
问题 I am using Knockout a lot and often times I have to write scripts inside the data-bind attributes. Is there any validation tools that I can use on these markup files to validate the javascript inside data-bind attributes? Would be nice if there is a grunt plugin. 回答1: There probably isn't (a prominent) one, because it's not common to have a lot of complex logic inside your view. With MVVM-like approaches it works best if you keep the View rather plain, and write out logic in your ViewModel

see all extenders and custom bindings for observable

淺唱寂寞╮ 提交于 2020-01-06 03:08:37
问题 Is it possible to see all extenders and bindings attached to an observable within Knockout JS? Sample View Model: var viewModel = function(){ var self = this; self.firstName = ko.observable().extend({required: "Please enter a name", logChange: "first name" }); self.lastName = ko.observable().extend({ required:true}); } I am also using several custom bindingHandlers including the Knockout X-Editable Plugin in addition to the KO Validation Plugin Sample Multi-Page View: <!--Screen 1 --> <input

Knockout validation after Mapping

两盒软妹~` 提交于 2020-01-05 04:18:12
问题 I'm new to knockout so please bear with me. I'm trying to using mapping plugin to map the Json data received from server to an existing viewModel instance. I'm able to do this without any issue. But in my viewModel I have used validation plugin so as soon as I map data and bind it to the UI, validation kicks and it immediately displays the error info. Is there way to not to display that error message until submit button is clicked. Or am I doing something wrong? Here is the Jsfiddle link For

Knockout validation message based set in the validation function

て烟熏妆下的殇ゞ 提交于 2020-01-04 08:23:07
问题 I want to set the message to display in the validation function of knockout similar to whats going on here: Knockout Validation Plugin Custom Error Message but without async. Heres what ive tried, but no validation message is displayed. this.name = ko.observable().extend({ validation: { validator: function (val) { return { isValid:val === 'a', message: 'the value ' + val + ' is not a' }; }, message: 'I dont want this default message' } }); JSFiddle is there a good way to do this? 回答1: close,

Knockout-Validation Using Regular Expression to Validate a Phone Number

烈酒焚心 提交于 2020-01-03 12:34:53
问题 I am trying to add a simple regular expression validation to one of my observables using Knockout-Validation. I have the following: self.ContactPhone = ko.observable().extend({ required: true, pattern: { message: 'Invalid phone number.', params: '^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$' } }); However, no matter what I enter, it returns the message 'Invalid phone number.' Is there a certain way I need to format the expression? I've tested it using purely JavaScript and it works fine. 回答1: You need

Add CSS Class with Knockout Validator

北战南征 提交于 2020-01-02 00:49:13
问题 I want to add a CSS Class to a select element in my view, my view model has a property which I've extended using Knockout-Validation: self.selectedRootCause = ko.observable().extend({ required: true }); Then my select is like so: <form data-bind="submit: closeComplaint" method="post"> <select data-bind="options: rootCauses, optionsText: 'RootCauseText', value: selectedRootCause, optionsCaption: 'Choose..', validationOptions: { errorElementClass: 'input-validation-error' }"> </select> <input

Knockout Validation Only If a specific button is pressed

送分小仙女□ 提交于 2019-12-31 03:47:10
问题 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

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

醉酒当歌 提交于 2019-12-30 07:54:12
问题 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

Knockout validation not firing with knockout custom binding

*爱你&永不变心* 提交于 2019-12-24 17:13:07
问题 I have a knockout custom binding handler for an input that I need to have validated by knockout-validation. However nothing I've done has worked. Validation is not fired. I can get validation firing on a plain ko value binding on an input bound to the same viewmodel property. What I've found from my research (ko docs, ko-validation github docs and this SO question validationOptions not working with custom bindingHandlers amongst many others) is that you need: ko.validation