Hey,
I have a problem that I’m trying to get the text on a button to change when a checkbox is checked, the code works and disables the button if the dates have expired and the expected text displays, but the text seems to get mixed up with the previous function that has run when you check the other checkbox. i.e. the first picture is as expected, buttons disabled and the text shows on the disabled buttons.
But when you click the 2019 box, the button enable, but the previous text stays… I have adjusted the code about 5/6 different ways but can’t get it to stop doing this, any ideas??
Here is my code, I have only given the code for 2 buttons to keep the code easier to read.
$w.onReady(function () {
currentYearButtonDisable();
for (let i = 1; i < 3; i++) {
$w(`#checkbox${i}`).onChange(() => {
const checkBoxes = ['checkbox1', 'checkbox2'];
let filtered = checkBoxes.filter(item => item !== `checkbox${i}`);
filtered.forEach((checkbox) => {
$w(`#${checkbox}`).checked = false;
});
if ($w('#checkbox1').checked) {
currentYearButtonDisable();
}
if ($w('#checkbox2').checked) {
nextYearButtonDisable();
}
});
}
});
function nextYearButtonDisable () {
var itemDate = $w("#dynamicDataset").getCurrentItem();
var DateOne= itemDate["dateOneYh"];
var DateTwo= itemDate["dateTwoYh"];
var currentDate= new Date();
if (DateOne, DateTwo !== undefined) {
if (DateOne<currentDate) {
$w("#bookhere1").disable();
$w("#bookhere1").label = "Trip Expired"
}
else $w("#bookhere1").enable();
if (DateTwo<currentDate) {
$w("#bookhere2").disable();
$w("#bookhere2").label = "Trip Expired"
}
else $w("#bookhere2").enable();
}
function currentYearButtonDisable () {
var itemDate = $w("#dynamicDataset").getCurrentItem();
var Date1= itemDate["dateone"];
var Date2= itemDate["dateTwo"];
var currentDate= new Date();
if (Date1, Date2 !== undefined) {
if (Date1<currentDate) {
$w("#bookhere1").disable();
$w("#bookhere1").label = "Trip Expired"
}
else $w("#bookhere1").enable();
if (Date2<currentDate) {
$w("#bookhere2").disable();
$w("#bookhere2").label = "Trip Expired"
}
else $w("#bookhere2").enable();
}