12
Required field validation works well when there is more of a checkbox available to select, but when there is only one available checkbox validation does not work.
This error also results if more fields to further validate the checkbox, validation is not performed, since the javascript checkbox is not correct.
To solve the problem in checkbox validation with a single option, you must modify the file formcheckbox.php located in the / root / class / xoopsform directory.
We must replace the line 241 (in the XOOPS version 2.5.0) that contains:
return NWLINE . "var hasChecked = false; var checkBox = myform.elements['{$eltname}'];" . "for ( var i = 0; i < checkBox.length; i++ ) { if (checkBox[i].checked == true) { hasChecked = true; break; } }" . "if (!hasChecked) { window.alert("{$eltmsg}"); checkBox[0].focus(); return false; }";
by
return NWLINE . "var hasChecked = false; var checkBox = myform.elements['{$eltname}']; if (checkBox.length) {for (var i = 0; i < checkBox.length; i++) {if (checkBox[i].checked == true) {hasChecked = true; break;}}}else{if (checkBox.checked == true) {hasChecked = true;}}if (!hasChecked) {window.alert("{$eltmsg}");if (checkBox.length) {checkBox[0].focus();}else{checkBox.focus();}return false;}";
This is because if there is only one option the element is not an array.
We must first check if the length is not null to determinate if there is only one or more options in the checkbox.
Reported in
trackerSatrebil
(Excuse me for my english)