When I view my page in preview, it works fine; when I load my page, it works fine; but when I use wixLocation.to(path) to move from one dynamic page to another, certain elements in repeaters don’t load properly. Things like setting the element.style property and .show()/.hide() don’t seem to work.
When logging within the onItemReady() of the repeater, it shows the correct values being logged, but the code seems to interact with the elements BEFORE the page is done switching to the new dynamic page but then load the default values of said elements.
wixLocation.to(baseUrl+path) works, but that seems to reload the page entirely as if you were going to a different site rather than navigating within the same site, if that makes any sense.
For example: the color options on the right are suppose to load with a red outline indicating the current color, when I click to another product, you can see the white is deselected and the yellow circle shrinks (which is part of the script so that the red outline and the actual color has some empty space in between), however then it just goes back to the default color of the circle element (which is the same red as the outline)
// the page's onReady calls a function that calls loadColorOptions()
async function loadColorOptions(color, product) {
let skuP1 = product['skuP1']
let currentColor = product[color][0]['value']
$w('#' + color + 'Text').text = 'Color: ' + currentColor
$w('#' + color + 'Repeater').onItemReady(($r, option) => {
colorOnReady($r, option, color, product)
})
await wixData.query('MyStore')
.limit(100)
.eq('skuP1', skuP1)
.distinct(color)
.then((result) => {
$w('#' + color + 'Repeater').data = result.items.sort(function (a, b) {
return sortColors(a, b)
})
$w('#' + color + 'Repeater').show()
})
}
function colorOnReady($r, option, color, product) {
let currentColorHex = product[color][0]['hex']
let currentColor = product[color][0]['value']
$r('#' + color + 'OptionCircle').style.backgroundColor = option.hex
if (option.hex === currentColorHex) {
$r('#' + color + 'OptionCircle').style.borderWidth = '4px'
$r('#' + color + 'OptionCircle').style.borderColor = '#FFFFFF'
$r('#' + color + 'OptionCircleOutline').show()
} else {
$r('#' + color + 'OptionCircle').style.borderWidth = '1px'
$r('#' + color + 'OptionCircle').style.borderColor = '#000000'
$r('#' + color + 'OptionCircleOutline').hide()
}
}
I have tried calling the functions using onChange(), after the wixLocation.to(), placing it in the dataset.onReady, but none of those work.
Is this a bug or what am I missing here?