Search code examples
google-app-maker

app maker: bind dropdown value to two datasource properties


I have a dropdown with years as options and I have 2 datasources which depend on the current year selected in the dropdown. In each datasource I created a parameter currentYear but I'm unable to bind the dropdown value to both parameters of the two separate datasources. Binding it to one datasource like @datasources.HolidayModel.properties.currentYearworks unsurprisingly.

Does anybody know, if it's possible to bind one value to two datasource properties? And if not, what would be a workaround without creating and binding the same dropdown twice?

any suggestions are welcome!


Solution

  • At this point dual bindings appear to be unsupported. Therefore this is only a workaround.

    Option 1:

    Leave the binding to the property of one of your datasources let’s call it datasource1 and put the following in the drop down onValueChange event:

    app.datasources.datasource2.properties.currentYear = newValue;
    app.datasources.datasource2.load(); //optional depending on where you load your datasources
    

    Option 2:

    Remove the binding on the drop down entirely and put the following in the drop down onValueChange event:

    app.datasources.datasource1.properties.currentYear = newValue;
    app.datasources.datasource2.properties.currentYear = newValue;
    //optional reload your datasources here
    

    Option 3:

    If your datasource is not a calculated one and your setup allows to set up both datasources as a query builder instead, then you can bind your query parameter directly to your drop down from the datasource settings. This would actually allow you to do this for practically limit less datasources. The datasource query parameter binding in this case would be:

    @pages.YourPage.root.descendants.YourDropDown