Jasper Duizendstra
Jasper Duizendstra

Reputation: 2617

Datasource in create and "normal mode for the same form

I would like to create a single form that I can bind to a datasource in create mode and in "normal mode". The use case is that I can have an existing item in the datasource that I would like to edit, or I would like to create a new one.

I can't find a way to dynamically switch the datasource mode before opening the form. It seems that 2 forms are required to accomplish this.

Any suggestions on how to accomplish this?

Upvotes: 0

Views: 144

Answers (1)

Pavel Shkleinik
Pavel Shkleinik

Reputation: 6347

It is possible to reuse form fields, but you'll still need at least two forms (containers). The idea is to create a page fragment with datasource derived from some model: Fields

then you can add this page fragment to form (container) and override datasource.

Form

Normally you would choose between normal mode:

@datasource.item

...and create mode:

@datasource.modes.create.item

You can find complete code sample in Project Tracker template and learn more about create mode in docs:

https://developers.google.com/appmaker/models/datasources#create_mode_datasource

Upvotes: 1

Related Questions