-1
I have a text string in the following format:
Size 35 (5 units)
I need to take the numbers inside the parentheses, run a function (which is already ready) and return a new number in place.
The problem is when the example is
Size 3 (3 units)
When I return the function, which is a subtraction, and there are two equal numbers, it updates the first number and not the one inside the parentheses, thus:
Size 2 (3 units)
And I need her to stay that way, in this example:
Size 3 (2 units)
My code is like this:
this.optionSelect = product.querySelectorAll("select");
//Lista todos os campos tipo SELECT
this.optionSelect.forEach(item => {
let selectText = item.options[item.selectedIndex].innerText;
//Pega o texto da tag OPTION
let removePar = selectText.split("(");
let replaceSelectQty = removePar.replace(/\D/g, '');
for (let match of selectText.matchAll(/\([^)\d]*(\d+)[^)\d]*\)/g)) {
var a = match[1];
item.options[item.selectedIndex].innerText.replace(a, parseInt(replaceSelectQty)-parseInt(this.inputQty.value));
//Atualiza o texto da tag OPTION, mas se o primeiro número for o mesmo da quantidade, ele atualiza o primeiro número e não a quantidade que está dentro dos parênteses
}
});