mardi 23 février 2021

Array of checkbox items, that if selected populate 4 dropdown lists, which then if selected in 1 dropdown removes that item from the other 3

I have a set of 38 translation languages that a client can currently choose from by means of 38 checkboxes. Once client chooses the total translations that are required, they can then decide which of these are the top 4 languages that go on the 2 primary faces of the packaging - 2 languages front, 2 languages rear, which are currently as 4 dropdown lists.

I have done a similar dependency lists set before(with much help from a friend), but this has been from a set list that does not vary depending on client choice.

Is there a way to add the selections from the checkboxes into this function as the 'buttonData'? Or just a better way of achieving this please?

Button Javascript:

loadP1Contents(["text_contents_p1"], {"A - Total Clean Shower Gel":[],"B - Carbon Protect 150ml Deo":[],"C - Clean Power Shower Gel":[],"D - Cool Power Shower Gel":[],"E - Invincible Grey Shower Gel":[],"F - Invincible Sport Shower Gel":[],"G - Hydra Energetic Shower Gel":[],"H - Hydra Sensitive Shower Gel":[],"I - Hydra Power Shower Gel":[]});

Function:

function loadP1Contents(fieldsData, buttonData)
{
var cChoiceArray = [[]];
var currentMenuLevel = 0;
cChoiceArray[currentMenuLevel] = ["Please Select...","-- None --"];
var subMenuCounter = [];
subMenuCounter[currentMenuLevel] = 0;

mutualExcludeFields = ["text_contents_p1","text_contents_p2","text_contents_p3","text_contents_p4","text_contents_p5"];
mutualExcludeChoices = [];

for (i = 0; i < mutualExcludeFields.length; i++) {
mutualExcludeChoices.push(this.getField(mutualExcludeFields[i]).value);
};

for (var choiceToAdd in buttonData) {

var alreadyPresent = false;
for (i = 0; i < mutualExcludeChoices.length; i++) {
if (mutualExcludeChoices[i] == choiceToAdd) {
alreadyPresent = true;
};
};      

if (!alreadyPresent) {
if (buttonData[choiceToAdd][0] == "sub") {
currentMenuLevel += 1;
subMenuCounter[currentMenuLevel] = buttonData[choiceToAdd][1];
cChoiceArray[currentMenuLevel] = [choiceToAdd];
} else {
cChoiceArray[currentMenuLevel].push(choiceToAdd);
subMenuCounter[currentMenuLevel] -= 1; 
};
while (currentMenuLevel > 0 && subMenuCounter[currentMenuLevel] < 1) {
currentMenuLevel -= 1;
cChoiceArray[currentMenuLevel].push(cChoiceArray[currentMenuLevel+1]);
subMenuCounter[currentMenuLevel] -= 1; 
};
};
};

var cChoice = app.popUpMenu(cChoiceArray[0]);

if (cChoice == "-- None --" || cChoice == "Please Select..." || cChoice == null || buttonData[cChoice][0] == "sub") {
for (i = 0; i < fieldsData.length; i++) {
this.getField(fieldsData[i]).value = "-";
}
} else {
this.getField(fieldsData[0]).value = cChoice;
for (i = 1; i < fieldsData.length; i++) {
if (buttonData[cChoice][i-1] != null) {
this.getField(fieldsData[i]).value = buttonData[cChoice][i-1];
} else {
this.getField(fieldsData[i]).value = "N/A";
}
}
}
};



Aucun commentaire:

Enregistrer un commentaire