Help with javascript for multiple Database join elements rendered as checkbox

I have 5 database join elements rendered as checkboxes.

Selection A
Selection B
Selection C
Selection D

Selection X

They all select the same data (an ID) from another table with a Where clause ordering the results.
The user is able to place a check in boxes A,B,C,D and if needed in X.
However if the user does not place a check in any boxes A,B,C,D then they shouldn't be able to check X.

The value of each element is stored in an array, so for example could look like this.
Selection A [3,8,9,15]
Selection B [9,15,12]
Selection C [3,9,15]
Selection D [12]

In this example a Selection X could be made if it resulted in any of the values 3 or 8 or 9 or 12 or 15 being inserted.

Does this make sense?
 
I have an example (only one dbjoin checkbox element, person___treff) with one "None" possibility and several others.
If "None" is checked it should uncheck all others, if any other is checked it should uncheck "None".
It's done in the form's JS file (com_fabrik/js/form_11.js here), in the checkbox element's JS box it just calls the function
Code:
TestTreff(this,event);
(onChange)
JavaScript:
requirejs(['fab/fabrik'], function () {
/* Test Treff dbjoin render as checkbox  (not for regular checkbox element) */
window.TestTreff = function(myobject,event) {
    var treff = Fabrik.getBlock('form_11',false).formElements.get('person___treff'); // get parent object

//Which checkbox has changed, checked true or false?; "None" has value=12 and is subElement[0]
//if "None" checked -> uncheck all others; if any other -> uncheck "None"
    var checkedYes = event.target.checked;
    if (event.target.value == 12 && checkedYes) {
        treff.update("12"); //updates the element with only value 12 (None) checked
    }
    if (event.target.value != 12 && checkedYes) {
        myobject.subElements["0"].checked = false; //unchecks the single checkbox
    }

}

});
So in your case something like (on each of your elements): if any option is checked enable Selection X.
 
Thanks to you both.
Troester I particularly like your solution but after fiddling with this and not really getting what I wanted, I decided to use a PHP validation instead.

I had 4 database join elements rendered as checkboxes if there wasn't a check in any of the 4 I didn't want to be able to check a fifth database join 'tbl_inspection_areas___dbj_optional'

this is a php validation that worked
PHP:
$arrs = array();

$arrs[] = $formModel->formData['tbl_inspection_areas___tab_label_a_raw'];
$arrs[] = $formModel->formData['tbl_inspection_areas___tab_label_b_raw'];
$arrs[] = $formModel->formData['tbl_inspection_areas___tab_label_c_raw'];
$arrs[] = $formModel->formData['tbl_inspection_areas___tab_label_d_raw'];

$list = array();

$optional = $formModel->formData['tbl_inspection_areas___dbj_optional_raw'];

foreach($arrs as $arr) {
    if(is_array($arr)) {
        $list = array_merge($list, $arr);
    }
}

$result = array_diff($optional, $list);


if (empty($result)) {
   return true;
}else{return false;}

Although I think a more capable person like you troester or startpoint would have made the js work.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top