jQuery Mobile and KO.js - two way binding with custom binging
HTML
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$( document ).on( "mobileinit", function() {
$.mobile.selectmenu.prototype.options.initSelector = ".mobileSelect";
});
</script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/knockout/2.3.0/knockout-min.js"></script>
</head>
<body>
jQuery Mobile data-* attribute
<fieldset data-role="controlgroup" data-type="horizontal">
<label><input type="radio" value="Yes" data-bind="attr: {name: 'VoteGroup1'}, checked: Vote" />Yes</label>
<label><input type="radio" value="No" data-bind="attr: {name: 'VoteGroup1'}, checked: Vote" />No</label>
<label><input type="radio" value="Abstain" data-bind="attr: {name: 'VoteGroup1'}, checked: Vote" />Abstain</label>
</fieldset>
<hr/>
Knockout.js custom binding
<fieldset data-bind="value: Vote, jqCheckboxRadio: { mini: 'true', type: 'horizontal' }">
<label><input type="radio" value="Yes" data-bind="attr: {name: 'VoteGroup'}, checked: Vote" />Yes</label>
<label><input type="radio" value="No" data-bind="attr: {name: 'VoteGroup'}, checked: Vote" />No</label>
<label><input type="radio" value="Abstain" data-bind="attr: {name: 'VoteGroup'}, checked: Vote" />Abstain</label>
</fieldset>
<hr/>
<p>
<select data-native-menu="false" data-bind="options: ['Yes','No','Abstain'], optionsCaption: 'Choose...', value: Vote" data-mini="true">
</select>
</p>
<script type="text/javascript">
ko.bindingHandlers.jqCheckboxRadio = {
init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var currentValue = valueAccessor();
$(element).controlgroup(currentValue);
$(element).attr("data-role", "controlgroup");
$( "input[type='radio']",element).on(...