Knockout Custom Binding Handler - Hidden Input

This function allows you to add change events to a Knockout Hidden Element
Knockout Custom Binding Handler - Hidden Input

ko.bindingHandlers.hiddenInputValue = {

init: function (element, valueAccessor) {

$(element).bind("change", function (event, data, formatted) { //hidden vars don't usually have change events, so we trigger $myElement.trigger("change");

var value = valueAccessor();

value($(this).val()); //rather than $(this).val(), might be best to pass our custom info in data

});

},

update: function (element, valueAccessor, allBindingsAccessor, viewModel) {

var value = valueAccessor();

$(element).val(value);

alert(value);

}

};

Last Updated: 3/27/2014 11:13:00 PM