I am pretty new to the Bubble and I need some good practice with managing data in my app. I use pages and groups with defined “Type of content” to add and edit elements within my database. It worked great in many cases, but I have read in one of the posts here that the approach for adding a new element, in this case, is to use a workflow, create a new “thing”, pass it to the page and allow a user to fulfil a form on the page/group and save data (modify thing).
The apparent problem appears when users are quitting the page in an “uncontrolled way”. Approach when there is no new “thing” built upfront, but only created after the user clicks Save solves this issue.
Am I doing something wrong or is this just a common issue and I can either find some trigger that will clean the database from those ghost elements or stop using pages with “Type of content” for adding new staff?
That is one method. Another would be to leave the data source for the groups empty by default and then add a conditional on the save button workflow. If Parent Group’s Thing is empty, create a new Thing and save the input values to the corresponding fields. If Parent Group’s Thing is not empty, make changes to Parent Group’s thing and save the input values to the corresponding fields.
You are correct that if a type of content is set on a page data must be passed. For this reason, I wouldn’t recommend using page content and a dedicated page as a means of creating data for the first time. This would be suitable for editing data or displaying details of a single record, but the hassle of having to clean up abandoned data outweighs the benefit of this setup for the purposes of data creation.
Instead, I would go with what @williamtisdale suggested - use a group instead. That way, you can optionally leave data blank when you are creating a new thing, and use a save button to create the data for the first time which would eliminate the risk of abandoned data in your database.
Let me know if you have any specific questions about this!
So as far as I understand I would need to have three separate pages:
for adding content (type of content not defined, editable inputs)
for editing content (type of content defined, editable inputs)
for read-only (type of content defined, labels instead of editable fields)
In theory, I could switch “This element is switchable” on a single page for edit and read-only.
Probably the editable input can be created as a reusable element to be used on add and edit pages instead of creating two similar pages.
You don’t NEED to have multiple pages, it’s really up to you and what you prefer.
Generally, I would have the “adding content” and “editing content” features be part of a popup reusable that can be used on any page, so that you can always trigger a workflow to show the popup and add/edit a record regardless of where you are in the app. You can use the technique @williamtisdale described where if the parent group’s data is empty, you know to create a record, and if the parent group’s data is not empty, you know to make changes to a record.
Then, I would probably have a single page for viewing details of a record. The advantage of having a separate page for this is that you can make use of the “slug” on the record to generate dynamic page URLs. For example, lets say that you were viewing a user profile on a page called “profile” with a type of content set to “user”
If I had a “slug” value set to “sammorgan” then I would be able to access my specific user profile at https://yourdomain.com/profile/sammorgan which is really handy for certain data types. The only way to achieve this type of dynamic URL within the page path is by using page content and data slugs.
To be clear, you can also have a separate page for adding content and editing content - that isn’t wrong. There are many ways to achieve things in Bubble, and ultimately, your preference and the way you can most easily stay organized matters!
Thank you. My users are creating quite complex thing, so I will probably go with the new page, but when using the reusable group, this will be quite simple and will not force me to duplicate any work. Once again: Thanks for quick help