Hi Kev1n,
Thanks again for the help, I managed get the depended dropdown form to work exactly as desired with the updating labels.
I think at the end to CONCAT the Caption|Label and dealing with it through JS was an elegant and easily scalable solution, many thanks for pointing that out.
I ended up having the following under the form's Custom Code > Edit:
Code: Select all
//Replace the Caption|Label with the caption and attach the Label to data()
function splitSelectLabel(id){
$('#'+id).find('option').each(function() {
var txt = $(this).text().split('|');
$(this).text(txt[0]).data({
label: txt[1],
});
});
}
//Sets a Select Object tier label based on the label saved in the previous Select Object tier's data
function setTierLabel(prevTierId, curTierId = undefined){
if(curTierId === undefined) { // Check if curTierId is undefined and then calculates it
//Split the selectId string and calculate the previous / next tier IDs
var NumTier = prevTierId.match(/\d/g);
NumTier.join("");
curTierId = 't' + (Number(NumTier) + 1) + '_id';
}
// Check if the previous tier ID object has a label defined under its data
let objTierIdData = $('#'+prevTierId).find(":selected").data();
if(objTierIdData.hasOwnProperty('label')){
//Set the next Tier ID Select's label
nuSetLabelText(curTierId, objTierIdData.label);
}
}
//On start loop through all the Select Object ids and check if they have a value (Populated on Edit)
//Then hide / unhide all Select objects, split Caption|Label, and assign Tier labels
var arrTierSelectObjects = ['t1_id','t2_id','t3_id','t4_id','t5_id','t6_id'];
arrTierSelectObjects.forEach(function (item) {
if(nuGetValue(item) == ""){
nuHide(item);
}else{
nuShow(item);
splitSelectLabel(item);
setTierLabel(item);
}
});
//On Select Object Refresh
function nuSelectObjectRefreshed(formId, selectId, count) {
//Split the selectId string and calculate the previous tierId
var NumTier = selectId.match(/\d/g);
NumTier.join("");
var prevTierId = 't' + (Number(NumTier) - 1) + '_id';
//Check if there is less than one element in the select or if the previous tier ID is blank
//Then hide / unhide the Refreshed tierId Select Object, split Caption|Label, and assign Tier labels
if ( (count < 1) || (nuGetValue(prevTierId) == "") ) {
nuHide(selectId);
} else {
nuShow(selectId);
splitSelectLabel(selectId);
setTierLabel(prevTierId,selectId);
}
}
Under each Select Object (t2_id~t5_id)> Select I have the following SQL based on the previous Select's value:
Code: Select all
SELECT
tblT2.tblT2_id,
CONCAT(COALESCE(tblT2.t2_name,''),'|',COALESCE(tblT2.t3_label,''))
FROM
tblT2
WHERE
((tblT2.t1_id = '#t1_id#'))
I ended up having to use COALESCE as well because CONCAT inserts "null" in the Select Object when a field in the table is empty.
Under each Select Object (t2_id~t5_id)>Custom Code I have a onchange routine refreshing each of the consequent Select objects:
Code: Select all
nuRefreshSelectObject('t3_id');
nuRefreshSelectObject('t4_id');
nuRefreshSelectObject('t5_id');
nuRefreshSelectObject('t6_id');