I make a program. Use price and category to query the data in the database. Look at the picture below.
These two queries are optional. In other words, the user can select or not select these two options to query. I use radioGroup to check prices. Use checkboxGroup to query category. I found that when using radioGroup, I can check whether its value is empty to determine whether it is selected by the user. The statement is very simple.
if ($w("#radioGroup1").value === "" )
But this method does not work for checkboxGroup. I used 3 statements below
if ($w("#checkboxGroup1").value === "")
if ($w("#checkboxGroup1").value === [] )
if ($w("#checkboxGroup1").value === null )
but them didn't work. see the image below. My question is in programming, how to detect whether the checkboxGroup is selected ? Hope to get help.
Well done, good luck and happy coding.
P.S. Use CODE-TAGs in future..... (just for CODE-SECTIONS)
$w("#checkboxGroup1").value[0]==="Animals" //If you just choose Person, you don't choose the other two. There will be $w("#checkboxGroup1").value[0]==="Person" //So the sentence that can detect whether $w("#checkboxGroup1) is selected by the user should be. if ($w("#checkboxGroup1").value[0]==="Landscape"|| $w("#checkboxGroup1").value[0]==="Animals" || $w("#checkboxGroup1").value[0]==="Person") //So I use the following programming statement. The program executed very well now. Thank you very much. export function button1_click(event) { if ($w("#checkboxGroup1").value[0]==="Landscape"|| $w("#checkboxGroup1").value[0]==="Animals" || $w("#checkboxGroup1").value[0]==="Person") { $w("#dataset1").setFilter( wixData.filter() .hasSome("imageCategory", $w("#checkboxGroup1").value) ) .then( () => { console.log("Dataset is now filtered"); }) .catch( (err) => { console.log("Dataset is not filtered"); } ); } }
Try this one....
if ($w("#checkboxGroup1").value[0] === "Landscape" ) if ($w("#checkboxGroup1").value[1] === "Animals" ) if ($w("#checkboxGroup1").value[2] === "Person" )
A group means that there are several values in it, right?
Like an ARRAY ---> myArray = [] ----> ["Animals", "Persons", "Landscapes", "and more"]
myArray[0] = ???
myArray[1] = ???
myArray[2] = ??? myArray[3] = ???
Test it yourself....
console.log(myArray[2])
console.log(myArray[0])
console.log(myArray)
let myArray = ["Animals", "Persons", "Landscapes", "and more"] console.log(myArray[2]) console.log(myArray[0]) console.log(myArray)
The same system is used in CheckBoxGroups.