Encountering an issue with a second round of text replacement within the function. The code runs without errors, but I'm unable to replace the "^" character in my 'template' string during a second 'replace' operation on a string variable.
I've tried various tests including running the 'else' statement independently and adjusting the conditional logic, but still struggling to append the 'secondary considerations' to the text replacement or replace the carrot placeholder at all.
This code involves working with the Shopify JSON API. The 'options' variable is obtained from a GET product request, which utilizes the 'options' JSON key and its values.
var createConfigsList = function(options) {
/* Container of options & product option we're working with */
var container = jQuery(".ta-OptionsContainer");
options.forEach(function(option, index, values) {
/* Name of option we're working with/also the label & select dropdown value */
var name = option.name;
/* Define formats for select boxes & value replacements */
var labelFormat = '<label>|</label>';
var selectFormat = '<select data-option="|" class="ta-CSelectDrop">';
var selectClose = '</select>';
var optionFormat = '<option data-value="|">^</option>';
if(name != "Title") { /* 'Title' is default Shopify variant option name */
/* Working HTML building variables */
var bLabel, bSelect, bOption, appendFormat;
/* Create the label & select box start */
bLabel = labelFormat.replace("|",name);
bSelect = selectFormat.replace("|",name);
/* List of values within this option set */
var values = option.values;
values.forEach(function(optVal) {
/* Define HTML building variable for this option tag */
var singleOption;
/* Create option; replace value placeholder w/ actual value */
singleOption = optionFormat.replace("|",optVal);
/* Secondary considerations for the text of the option tag */
if(name == "Length") {
singleOption.replace("^",optVal + " Length");
}
else if(name == "Depth") {
singleOption.replace("^",optVal + " Depth");
}
else {
/* If no special considerations, just do the replacement */
singleOption.replace("^",optVal);
}
/* Combine the option into the 'list' of options */
bOption = bOption + singleOption;
});
/* Close our select, and then append the new area to the display container */
appendFormat = bLabel + bSelect + bOption + selectClose;
container.append(appendFormat);
}
});