Complex composition pop-up

I’m creating an entry system that requires the user to specify the composition of their entry (wine, for example) on the registration form. For example, if they’re entering a red blend that is 50% merlot and 50% cabernet, I would like a pop-up that allows them to specify this and validates that the percentages add up to 100%.

The number of “things” they can add to this composition should not be limited, but the percentage should always add up to 100%.

Ideally, I’d like for them to be able to go back in and edit this after they’ve submitted the entry. I assume to achieve this, I’ll need to store these in a data type separate from my entry data type, but I don’t want to over complicate it.

I’m not sure the best way to design this or if there’s a plugin that may help with it. Any advice is welcome!

Have a datatype for composition_thing, with a field for the percentage, and a field to relate it to the parent thing.

Then you can just ensure the percentages add up to 100 before allowing them to save.

Forget a plug in, you need to do this natively otherwise it will end up more work and you will not learn anything!

Presumably there are a certain number of grape varieties? you could try the following:

  • create a option set of the known varieties in the back end of bubble, with a percentage attribute.
  • in your wine data type , create a composition field which has the variety option set as a list.
  • In your wine entry form, create a repeating group of varieties, with an add button to add one and some logic to give it 100%.
  • As a percentage always adds to 100, you can create some logic with number inputs storing to a custom state of between 0-100
  • This may need some experimentation, but what you could do is make the first variety un editable, as it will always be 100% if on its own, or a remainder of a sum of other varieties.

Now you can save the list of varieties to the wine, Voila!

1 Like

Do you mean a data type or an option set? I’m relatively new to bubble, but I don’t think I can add an attribute to an option set (beyond just listing the variety).

Yes you can create an option set, IE Cabernet, and add a attribute of percentage (which will be blank) which will be used to store the percentage of the option on the wine data type when you save it.

First of all, thank you for your help! Are you saying have one option set with all of the different varieties (option set = “varieties” and each attribute is a variety, i.e. merlot, cabernet, etc.) or one option set per variety (option set = “merlot” and put an attribute for each percentage (1-100))?

I probably wouldn’t use an Option Set for grape varieties - the database might be more suitable for this… (but like everything, it depends on the specifics of your use case)…

But in any case, you’ll have to use the database to store the user-entered percentages of each variety… (if that’s what you’re trying to do)…

2 Likes

Sorry, yes you are right. Create your list of varieties in option sets as it is fixed and store your composition as its own data type against a wine.

1 Like

Thank you @adamhholmes - I’m seeing two different data types, one that I use to store the list of varieties, and a second to create a relationship between the entry and the associated variety that also stores the percentage. Is that what you mean? I’d use an option set for the varieties, but I don’t think I can do an import of them (and there are hundreds).

Yes exactly… you need two separate data entities… 1 for the varieties, and one for the variety_data

I’d only generally use an option set if there are a small number of things (maybe less than 20) and/or they never change and will never need to be added or deleted by a User…

For anything else (such as grape varieties) I’d use the database (it’s much easier to create them, view them, edit them - and they can be added by Users, which option sets can’t)… plus there may be additional performance advantages to keeping them in the database rather than using an option set if the list is very large.

But, it’s really up to you.

2 Likes

This topic was automatically closed after 70 days. New replies are no longer allowed.