Auto-binding feature updates the database for you. Removing the need of a workflow. This can make your app faster and easier to manage.
Let's say you have an input field which displays some initial content. You allow your user to update that field. Normally, you would need a workflow to update the database with the updated value.
With auto-binding however, the database will be updated without requiring any workflow.
The first thing that we need to do is set the Privacy rules. Privacy rules in Bubble allow you to define who has permission to access and modify data. If you have multiple user types, you can define multiple rules.
Defining a new Privacy rule
To create these rules, simply head to the Data tab > Privacy.
The Privacy rules are defined for each data type separately. Here, I am defining the Privacy rules for CartItem data type.
Click on 'Define a new role' to open a popup where you can define the role name, say Admin. There are now 2 user types, one is the Admin and the other is Everyone else. But which users come under Admin? We need to define that.
Under the Admin user type, there is a field for us to define the users who will have these privileges. I have an Admin field of Yes/No type in my database and I want the users who have Admin as Yes to have these privileges. So just like you use dynamic data, I can simply define the Admin role.
Once it is defined, I want the Admin to be able to use Auto-binding feature. I can further specify the fields that I want to be able to be updated and can leave out the fields that I don't want.
For Everyone else, a good practice is to not expose any data to them. Instead create a new role for the data's creator. So that only the creator can access the data apart from the admin.
Input element settings
The last step is to allow Auto-binding on the input element. Create an input element according to your requirement. Make sure that the parent group of the input element has a Type of content and Data source defined. For example, it can be Current User's Name etc. In the current case, I have defined it like this.
The dropdown has a parent group and I am searching for the correct CartItem to edit. This is important as without this, Bubble will not know which database entry it should modify.
All the input fields have an Auto-binding checkbox which you can tick and define the appropriate field to modify.
As you can see, I am updating the Quantity field. The Content format and input element has to be correct according to the database.