and now the select widget is showing me the options to select . My question is now i wanna create the button that when i click on it runs the selected Querie in the select widged , how do i do that ?
can anybody please stir me in the right direction ?
Hey @Dameats, this is possible in Appsmith using the onOptionChange property from the select widget. On the JSObjects, you could write a simple if-else condition or a switch statement to handle queries. Here’s an example:
I have two APIs – API1 and API2
On my JS Object, I’ve created a function with a simple if-else statement.
export default {
myFun1: () => {
if(Select1.selectedOptionValue === "Api1"){
let data = Api1.data;
storeValue("APICALL", data);
return "Call from API1"
}
else{
let data = Api2.data;
storeValue("APICALL", data);
return "Call from API2"
}
},
}
Here, based on the selected value, I’m storing an overriding local appsmith variable (named APICALL) with the storeValue function.
I call this function whenever the selected option changes, so in my onOptionChange property I use this:
{{JSObject1.myFun1()}}
I’m printing the output on the text-widget for reference:
Please note that this could be more well written with a switch statement if you have multiple queries.
My buttons onClick looks like this : {{JSObject1.runQuery(Select1.selectedOptionValue)}}.
You could also place this directly in the select widgets onOptionChange event as well