Below you will find pages that utilize the taxonomy term “Knockout”
Knockout Validation: Multiple email addresses
A simple rule for validating an observable which could contain multiple email addresses.
Assuming you have an observable like self.emailTO = ko.observable('');
, you would just extend it to have self.emailTO.extend({ multiemail: true });
. Use it with the required validator if you want at least one email address.
ko.validation.rules['multiemail'] = {
validator: function (val, validate) {
if (!validate) { return true; }
var isValid = true;
if (!ko.validation.utils.isEmptyVal(val)) {
// use the required: true property if you don't want to accept empty values
var values = val.split(';');
$(values).each(function (index) {
isValid = ko.validation.rules['email'].validator($.trim(this), validate);
return isValid; // short circuit each loop if invalid
});
}
return isValid;
},
message: 'Please enter valid email addresses (separate multiple email addresses using a semicolon).'
};
Requires Knockout.js, Knockout Validation, and jQuery.
Custom Debug JsRender tag
I’ve been learning a lot about JsRender and Knockout.js after finding Ryan’s answer on StackOverflow. I’ve created a couple of templates and started to use the {{for}}{{/for}}
tag.
I was having trouble figuring out how to access the parent object’s data from within the for loop. After reading John Papa’s awesome posts, Using JsRender with JavaScript and HTML and Advanced JsRender Templating Features I came up with a quick custom “Debug” tag to help me understand.