Setting error message in html with knockout validation -
i use knockout-validation adding validation rules in html5, works great:
http://jsfiddle.net/gt228dgm/1/
i change default error messages generated browser (like "this field required." or "invalid"). pretty done in javascript code, believe kind of texts should go html. possible , how? guess i'm looking like:
<input data-bind='value: firstname, validate: { message: "please enter first name" }' required pattern="^[a-za-z]{1,255}$"/></label>
i have implemented custom knockout binding solves issue:
ko.bindinghandlers.validate = { init: function(element, valueaccessor, allbindings, viewmodel, bindingcontext) { var valuebinding = allbindings().value; var value = valueaccessor(); if (value) { valuebinding.extend(value); } } };
the binding looks this
<input data-bind='value: firstname, validate: { required: { message: 'full name missing' }, pattern: { message: 'full name should max. 255 alphanumeric characters' } }' required pattern="^[a-za-z]{1,255}$"/>
any other suggestions?
Comments
Post a Comment