Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

make sure that at least one checkbox is set

I have a checkbox group containing two checkboxes 'manual' and 'automatic'with a default value of 'manual'. I have writtent some javascript code which is execute from the checkbox groups change event.

One value must be set at all times. if manual is selected only and you try to un-select it the change event code forces it to be re selected. If automatic ise currently selected and you try to un-select it then it should be unchecked and the manual option should be rechecked. The code to do this is actually executing as I have debugged it using breakpoints in chromes developer tools.

However, the manual check box remains unchecked, leaving both unchecked which is an error condition. He is a screen shot showing the javascript in the debugger:

Image

I can't use a radiobox by the way because both checked is valid.

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

make sure that at least one checkbox is set

I found the solution .checkboxradio('refresh') fixed it.

codefunction checkTransmission() {
console.log("transmission checkbox group value changed");
var manualIsChecked = $("#reg2_manual_checkbox").is(":checked");
var automaticIsChecked = $("#reg2_automatic_checkbox").is(":checked");
if (!(manualIsChecked || automaticIsChecked)) {
$("#reg2_manual_checkbox").prop("checked", true).checkboxradio('refresh');
}
}/code

Return to “Issues”