Reputation: 20078
UPDATE: the below code is firing the event but the only issue I'm having is: its not unchecked the checkbox, which is
$("input#crea").is(':checked') == false;
I'm using ICheck plugin, what I'm trying to do is to: User should select only one checkbox and user can not check both....
$('input').on('ifChecked', function (event) {
if ($("input#rec").is(':checked')) {
$("input#crea").is(':checked') == false;
}
else if ($("input#crea").is(':checked')) {
$("input#rec").is(':checked') == false;
}
});
Below is the rendered page looks like at the run time:
<div class="col-sm-6">
<input class="icheck" id="rec" name="rec" type="checkbox" value="true" /><input name="rec" type="hidden" value="false" /> <span style="color:black;">Receive</span>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"> </label>
<div class="col-sm-6">
<input class="icheck" id="crea" name="crea" type="checkbox" value="true" /><input name="crea" type="hidden" value="false" /> <span style="color:black;">Create</span>
</div>
</div>
Upvotes: 0
Views: 4589
Reputation: 1
You should uncheck checkbox like following:
$("input#crea").iCheck('uncheck');
$("input#rec").iCheck('uncheck');
You can find more information in the documentation
// change input's state to 'checked'
$('input').iCheck('check');
// remove 'checked' state
$('input').iCheck('uncheck');
// toggle 'checked' state
$('input').iCheck('toggle');
// change input's state to 'disabled'
$('input').iCheck('disable');
// remove 'disabled' state
$('input').iCheck('enable');
// change input's state to 'indeterminate'
$('input').iCheck('indeterminate');
// remove 'indeterminate' state
$('input').iCheck('determinate');
// apply input changes, which were done outside the plugin
$('input').iCheck('update');
// remove all traces of iCheck
$('input').iCheck('destroy');
Upvotes: 0
Reputation: 20740
You should uncheck checkbox like following.
$("input#crea").prop('checked', false);
$("input#rec").prop('checked', false);
Full event should look like below.
$('input').on('ifChecked', function (event) {
if ($("input#rec").is(':checked')) {
$("input#crea").prop('checked', false);
}
else if ($("input#crea").is(':checked')) {
$("input#rec").prop('checked', false);
}
});
Upvotes: 2