I'm creating ajax based application. Now I'm working with client side javascript. I created controller which works correctly according to application logic, but i have problems with updating views which contains checkboxes. Here is short example of what I'm doing:
<script type='text/javascript'>
var model = { 'chk1': true, 'chk2': false, 'chk3': false };
var Controller = {
'processCheck': function(chk, value) {
model[chk] = value;
if (chk == 'chk2')
model.chk2 = true;
if (chk == 'chk3' && value)
model.chk1 = false;
if (chk == 'chk1' && model.chk3)
model.chk1 = false;
Controller.updateView();
},
'updateView': function() {
$('#chk1').attr('checked', model.chk1);
$('#chk2').attr('checked', model.chk2);
$('#chk3').attr('checked', model.chk3);
}
}
</script>
<input id='chk1' type="checkbox" onclick="Controller.processCheck('chk1', $('#chk1').attr('checked')); return false;" />
<input id='chk2' type="checkbox" onclick="Controller.processCheck('chk2', $('#chk2').attr('checked')); return false;" />
<input id='chk3' type="checkbox" onclick="Controller.processCheck('chk3', $('#chk3').attr('checked')); return false;" />
So logic is very simplified. Problems occurs when we click on checkboxes. They are updated incorrectly. But if I call controller methods with appropriate parameters, and then check model, all seems to be correct. So problem is with click event in checkboxes. I did not have any problems with input fields and dropdowns.