I have a repeating group that lists the ingredients of a recipe, along with quantity and unit. Ingredients are their own data type, while qty / unit are columns within the recipe type.
I have the trashcan set to set custom state, minus item current cell’s ingredient - this successfully removes that row’s ingredient and attributes tied to that ingredient (such as calories). It doesn’t however remove the rest of the row on the repeating group. I tried setting another custom state just for ‘Qty’, but when I remove ‘current cell’s index’ it instead removes any quantity value matching that cell’s index (so if I click ‘trashcan’ on line 2, it removes any line’s quantity with a qty value of 2).
Is there a different way I should approach this? Is there a way to simply remove an entire row of a repeating group regardless of data type?
Try using this conditional on the RG cell’s main group (container group) " if current cell’s ingredient is empty" then “This item is invisible”. This should hide the entire row when the ingredient is removed.
That was a great idea I hadn’t considered, although upon trying this a few different ways, it seems it doesn’t solve the issue, because once the ingredient is ‘minused’, that cell’s ingredient is not empty, it just now contains the ingredient from the line below…
The problem is with the database structure here. You see you are saving two different lists (ingredients and QTY) but there is no link between the two to specify which item in list 1 relates to which item in list 2. Depending on index is what’s causing the problem. Let me show you 2 solutions. 1st is a quick hack according to your current setup (Not recommended but should work). 2nd is the correct approach.
I believe your are removing the ingredient using the clicked-on event. Add more actions to the event “When icon Trashcan is clicked” to remove the index# QTY from the QTY custom state as well (and any other items that need to be removed when ingredient is removed).
You will need to understand the concept of THINGS, or SETS (or boxes). Let’s say you have 10 patient’s blood samples in one box, and the corresponding labels in another box. How does the lab know which sample belongs to what patient? Simply lining the blood sample capsules up in lines wont make this right. If we take out one item and reset the arrangement to start from 0, the reports will be messed up.
When you have two or more things that need to be together for something to make sense, you need to treat them as a set. For example, Ingredient and QTY make no sense independently. They will only mean something when they are linked. This makes a set (or box) of items that are linked to each other and make sense together.
Ideally every set should be a separate thing in the database. In your use case you need a box to put in ingredient and the corresponding QTY.
Create a new thing called “Recipe item” , add two new fields “Ingredient” (of type ingredient if you have it as a separate thing in the db), and “QTY” of type number.
Add any additional fields that you may need.
Then have the recipe contain a list of “Recipe items”.
(Optional)Add the selected Recipe to a custom state (so that you don’t modify the actual entry in the database unless you want to).
Now your RG will have a data source "Custom state’s recipe’s “recipe items”, and every field in a row will be a part of the recipe item so you can remove the entire row by removing the recipe item by using :minus item.
I hope this helps (and makes sense). Feel free to ask if you have any questions
A recipe type is comprised of a list of ingredients type, and then the Qty & Unit. That tie to ingredients is what pulls in each ingredient’s Calories, ABV, etc.
Yes I did try this, and while it sort-of worked as I mentioned in the original post, the problem I encountered was the ‘Current Cell’s Index’ was removing any Quantity with a value of that index. So if I clicked the trashcan on line 2, it would remove any quantity of 2oz.
Understood on both of these - I hope my details about how I structured the Recipe type in the database clarifies this - any reason my existing structure wouldn’t work as-is? I believe what you’re referring to (creating a 3rd thing known as Recipe items) is known as a ‘junction table’, although I had been led to believe bubble didn’t require junction tables as linking one type to another, it does the work for you.
Thank you for sharing the db screenshot. The issue is that in the db ingredients QTY and other items do not have a link to each other. Relating them on the basis of #index works but only takes you so far. It will not only create problems ahead but also make the calculations much more difficult for even the smallest tasks (like the issue in this post). Having a dedicated thing for each set not only makes it easier to implement logic, but also takes the complexity out of the data storage and processing.
This could happen if you are using “:Minus item Page content’s Recipe’s Qty:item #Current Cell’s Index’s Value”. Since this translate to a string so Bubble will delete all the text entries matching that text.
I was finally able to wrap my mind around this and made some changes to the DB, creating a new data type called ‘Recipe-Ingredient’ which is an Ingredient, fields for Qty, Unit, and Name. I re-worked all of the sandbox recipes I’m using into it, and re-wrote the repeating group to reference a recipe’s ‘recipe ingredients’ instead. It works flawlessly, and I really appreciate you pointing me in the right direction-
Hi Matt. I’m happy that I was able to help you with this. And you are not alone scratching your head when you hear about these concepts at first. Everyone of us must go through this evolution
These concepts are fairly difficult to digest at first but the more you practice, the easier it gets. After a few implementations it becomes natural for you and you do not have to even think about it anymore.
If you have any further questions, please let me know and I’d be happy to help