Search code examples
google-app-maker

Appmaker Input Form, change options based on earlier dropdown choices


Hypothetical:

Say i'm having someone order a cake and they choose vanilla or chocolate, and then they have to choose a frosting

if vanilla: strawberry or buttercream   

if chocolate: mocha, dark chocolate or buttercream.

Right now the frosting value in the data model can accept all four options, so all four show up in the dropdown.

a) is there a way to change the binding for the second dropdown after the first is chosen?


Solution

  • Im guessing you set the dropdown "possible value" options in the data source and you have those fields as just string fields in your table.

    the quick and dirty way to do this is go to the Cake drop down and on the Property Editor>Events>OnValueChange select Custom Action and use this Code

    if(widget.value==="Vanilla"){
       widget.root.descendants.Field.options = ['Strawberry','Buttercream'];
    }else if (widget.value === "Chocolate"){
      widget.root.descendants.Field.options = ['Mocha','Dark Chocolate','Buttercream'];
    }
    

    "Field" here is replaced with the name of the dropdown box for your frostings

    also go to the property editor of the frostings dropdown and delete everything in the options field there.