Skip to content

Commit

Permalink
testing fix: #34
Browse files Browse the repository at this point in the history
  • Loading branch information
kml27 committed Sep 18, 2018
1 parent c589262 commit a407107
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,13 @@ function setMemberByType(src, dest, control)
if(String(control.onclick).search("setDependentDisabledState")!=-1){
control.onclick();
}

//for radios, the onchange event is on the parent fieldset
if(control.type!=undefined && control.type=="radio"){
var parentFieldset = getFieldsetsWithRadios(control);
parentFieldset.onchange();
}

}

function versionedDataStore(datastore, control){
Expand Down Expand Up @@ -532,24 +539,38 @@ function applyScrollPositionPersistence(){
});
}

function getFieldsetsWithRadios(){
function getFieldsetsWithRadios(specificChildRadio=undefined){

var fieldsets = jQuery.makeArray($('form#htmlform fieldset'));

var fieldsetsWithRadios = fieldsets.filter( (fieldset) => {
if(fieldset.id=="") {
//console.log("Skipping", fieldset);
return false;
}
if(fieldset.id=="") {
//console.log("Skipping", fieldset);
return false;
}

//see if there are any child radios for the given fieldset
var fieldsetHasRadios = $(`fieldset[id=${fieldset.id}] input[type=radio]`).length>0;

//check if this fieldset has any children fieldsets (which may account for the radios we see)
var isImmediateParent = $(`fieldset[id=${fieldset.id}] fieldset`).length==0;
var fieldsetHasRadios = false;
//if only looking for a specific parent, check for that specific child first
if(specificChildRadio!=undefined){
var specificRadio = $(`fieldset[id=${fieldset.id}] input[type=radio][id=${specificChildRadio.id}]`);

//if the specific radio was not selected, then reject this parent now
if(specificRadio[0]){
return false;
}

fieldsetHasRadios = true;
//else check that it is not a parent fieldset of the specific fieldset we want
} else {
//see if there are any child radios for the given fieldset
fieldsetHasRadios = $(`fieldset[id=${fieldset.id}] input[type=radio]`).length>0;
}

//check if this fieldset has any children fieldsets (which may account for the radios we see)
var isImmediateParent = $(`fieldset[id=${fieldset.id}] fieldset`).length==0;

//if this is not a parent of fieldset and it has radio children, keep it
return fieldsetHasRadios && isImmediateParent;
//if this is not a parent of fieldset and it has radio children, keep it
return fieldsetHasRadios && isImmediateParent;

});

Expand Down

0 comments on commit a407107

Please sign in to comment.