Hey Wix team,
I have a question about using functions, I was wondering how to stop a function running i.e. if you toggle between two radio buttons, how can you stop the other function from running?
export function radioGroup2_change(event) {
let itemObj = $w("#dynamicDataset").getCurrentItem();
if ($w("#radioGroup2").value === "1") {
currentYearButtonDisable()
checkAvalibilityDateOne()
}
if ($w("#radioGroup2").value === "2") {
nextYearButtonDisable()
checkAvalibilityDateTwoYH()
}
}
The issue I have is that when I toggle the radio button it still leaves the other function that has run i.e. elements that show in one of the functions
When you toggle between the two options, you need to toggle everything . That is, if you choose one option and then disable something, you need to make sure you “reset” (e.g. enable) the other option.
Something like this:
export function radioGroup2_change(event) {
let itemObj = $w("#dynamicDataset").getCurrentItem();
if ($w("#radioGroup2").value === "1") {
currentYearButtonDisable();
nextYearButtonEnable();
checkAvalibilityDateOne();
}
else if ($w("#radioGroup2").value === "2") {
currentYearButtonEnable();
nextYearButtonDisable();
checkAvalibilityDateTwoYH();
}
}
You of course know all of your code and what you are trying to do, so you might need to perform additional actions.
Hopefully this will get you going in the right direction.
@yisrael-wix Thank you, that works! The only issue is that I have 12 dates… so looks like I would need 24 functions, I think I’m being very inefficient with my code here:
export function radioGroup1_change(event) {
if ($w("#radioGroup1").value === "1") {
checkAvalibilityDateOne()
checkAvalibilityDateTwoDisable()
}
if ($w("#radioGroup1").value === "2") {
checkAvalibilityDateTwo()
checkAvalibilityDateOneDisable()
}
}
function checkAvalibilityDateOne(){
let course = $w('#dynamicDataset').getCurrentItem()
wixData.query("Course_Availbility")
.eq('courseId', course._id)
.eq('date', course.dateOne)
.ge('numberOfParticipants', $w('#minParticipantsText').text)
.find()
.then((results) => {
if (results.totalCount > 0){
$w('#courseStatusTextOne').show();
}
})
}
function checkAvalibilityDateOneDisable(){
let course = $w('#dynamicDataset').getCurrentItem()
wixData.query("Course_Availbility")
.eq('courseId', course._id)
.eq('date', course.dateOne)
.ge('numberOfParticipants', $w('#minParticipantsText').text)
.find()
.then((results) => {
if (results.totalCount > 0){
$w('#courseStatusTextOne').hide();
}
})
}
function checkAvalibilityDateTwo(){
let course = $w('#dynamicDataset').getCurrentItem()
wixData.query("Course_Availbility")
.eq('courseId', course._id)
.eq('date', course.dateTwo)
.find()
.then((results) => {
if (results.totalCount > 0){
$w('#courseStatusTextTwo').show();
}
})
}
function checkAvalibilityDateTwoDisable(){
let course = $w('#dynamicDataset').getCurrentItem()
wixData.query("Course_Availbility")
.eq('courseId', course._id)
.eq('date', course.dateTwo)
.find()
.then((results) => {
if (results.totalCount > 0){
$w('#courseStatusTextTwo').hide();
}
})
}
This is obviously only for 2 dates, would love to have your thoughts on this.
Thank you for your time and effort 