Hi all,
I’m applying some AJAX to a checkbox to get it to auto update a model when checked. But no matter what I do, I can’t get the checkbox to toggle. The model updates fine. I’ve used FireBug to verify that the return values are returning as expected. I’m not getting any errors.
I’ve tried using every conceivable trick I’ve been able to find to change the checked value of the checkbox, the most straightforward of which is:
ON
$('.myCheckbox').attr('checked','checked')
OFF
$('.myCheckbox').removeAttr('checked')
But the checkboxes won’t toggle as long as AJAX is applied – even if I don’t try to apply my returned values.
Here’s my code, where I’ve tried to attach the checked status to the return values:
foreach($recommenderTypes as $type) {
$checked = isset($validRecommenders[$type->id]);
?>
<?php echo CHtml::checkBox('recommenderType_'.$type->id, $checked, array(
'ajax' => array(
'type'=>'POST', //request type
'url'=> $this->createUrl('admin/programType/ajaxCheckboxToggle'),
'dataType'=>'text',
'data' => array('ap_programType_id' => $model->id,'ap_recommenderType_id' => $type->id),
'success' => 'js:function(vals){
if (vals == 0) { $(this).removeAttr("checked"); }
else if (vals == 1 ) { $(this).attr("checked","checked"); }
else alert("Server disconnect. Please reload the page and try again.");
}',
'error'=>'function (xhr, ajaxOptions, thrownError){
alert(xhr.statusText);
alert(thrownError);}',
),
'prompt' => Yii::t('app','- select -'),
)); ?> <?=$type->name?><br />
<?php } ?>
Any ideas? Is this a JUI bug?
Thanks!