Dear Chronoengine
I am trying to limit the amount of checkboxes that can be selected (exactly14 out of 20 boxes) and followed all the steps in this topic:
https://www.chronoengine.com/forums/posts/f26/t90709.html?page=2
I'm using:
Joomla Beez template
Chronoforms 4.05
Joomla 3.23
I used the code in the topic and made the following changes as per the topic:
Changed the first checkbox id to: input_checkbox_group_7_0
Changed the form name in the 3 lines to: nomin2
Used both:
var group = el.getSiblings(['input']);
and without the square brackets,
var group = el.getSiblings('input');
Also saved the form type as Custom and removed checkbox divs (when doing the form in Wizard it seems to add divs to all the checkboxes in the group)
Then added the JS code first before Show html, into Events, On Load, Load JS
Dynamic file settings: I tried Yes and No
I tried everything I could, but nothing seem to have any effect on limiting the checkbox selections.
Here is my latest attempt at the JS code:
http://www.fineartist.co.za/solar/index.php?option=com_chronoforms&chronoform=nomin2
Dearly hope you can point me in the right direction. I am not a coder and am probably overlooking something totally silly.
Francois
Herewith the JS code I used:
I am trying to limit the amount of checkboxes that can be selected (exactly14 out of 20 boxes) and followed all the steps in this topic:
https://www.chronoengine.com/forums/posts/f26/t90709.html?page=2
I'm using:
Joomla Beez template
Chronoforms 4.05
Joomla 3.23
I used the code in the topic and made the following changes as per the topic:
Changed the first checkbox id to: input_checkbox_group_7_0
Changed the form name in the 3 lines to: nomin2
Used both:
var group = el.getSiblings(['input']);
and without the square brackets,
var group = el.getSiblings('input');
Also saved the form type as Custom and removed checkbox divs (when doing the form in Wizard it seems to add divs to all the checkboxes in the group)
Then added the JS code first before Show html, into Events, On Load, Load JS
Dynamic file settings: I tried Yes and No
I tried everything I could, but nothing seem to have any effect on limiting the checkbox selections.
Here is my latest attempt at the JS code:
http://www.fineartist.co.za/solar/index.php?option=com_chronoforms&chronoform=nomin2
Dearly hope you can point me in the right direction. I am not a coder and am probably overlooking something totally silly.
Francois
Herewith the JS code I used:
window.addEvent('domready', function() {
var checkbox;
checkbox = $('input_checkbox_group_7_0');
checkbox.addClass("validate['%countCheck']");
if ( typeof formCheck_nomin2 !== 'undefined' ) {
formCheck_nomin2.dispose(checkbox);
formCheck_nomin2.register(checkbox);
}
});
var countCheckMax = 3;
var countCheckMin = 1;
function countCheck(el) {
var group = el.getSiblings(['input']);
group.include(el);
var count = 0;
group.each(function(item) {
if ( item.checked ) {
count++;
}
});
if ( count > countCheckMax ) {
el.errors.push("You can only check "+countCheckMax+" items");
return false;
} else if ( count < countCheckMin ) {
el.errors.push("Please check at least "+countCheckMin+" items");
return false;
} else {
return true;
}
}