In my app, a User can select a product from a dropdown list. That works fine. I now want the first item in the list to always be “Add New Item” so that when they select this option, a “New Item PopUp Loads”. Is this possible?
I did find a thread on here where someone alluded to being able to do this but I wasn’t able to follow the methodology laid out in it with the example given and it’s a 5 year old thread now so I hoped that someone might be able to point me towards achieving this using Bubble’s current abilities.
Many thanks
Yes, it is possible.
I’m not on my pc right now to say exactly step by step, but basically it would be as follows.
I usually use an option set with some option like “Add new item”, this is because it will also be part of the dynamic data source of the dropdown and as we know, the dinamic source of a dropdown needs to be a list even if in that list there is only one item, which is the case for this option set. So in the dropdown data source I do a search for ALL OPTIONS of this option set and perform a “merged with” with the second data source, which would be the existing options. That way, the first option of the dropdown would be the option set, so now you can create a workflow and put a conditional that "When the dropdown has its value changed and this value is the value of the option set, then a popup window will open. For user experience reasons, also reset the dropdown value as the last step of this workflow, in some cases, depending on the structure of your form, it is necessary to group the dropdown and perform the “reset data” for the group.
No doubt there are multiple ways to achieve this… but, assuming the dropdown’s content-type is a custom datatype, one way you can do it is as follows…
-
Add a Yes/No field to whatever datatype the drop down is showing (call it something like ‘Add New’)
-
Create an entry in the database for that datatype, with a Name (or whatever field you want to display in the dropdown) of ‘Add New Item’ and set its ‘Add New’ field to ‘Yes’
-
Set your dropdowns DataSource to display all the entries, Sorted by the ‘Add New’ field, descending ‘Yes’
-
Then just run a workflow when the dropdown’s value is changes, only when the dropdown’s value’s Add New field is Yes
Note: if you’re using other constraints on your data source search then you might need to do 2 searches and merge them.
Thank you ever so much for this. Food for thought indeed.
I’ve just been called away for the rest of the day so I’ll have a look into this on Monday but I really appreciate your input. Thank you.
Best
Joe
I think I’m having a brainfart here (I’ll blame post Covid brain fog!)…
Can I ask what you mean by “assuming the dropdown’s content-type is a custom datatype”
My dropdown is currently getting its data from a “Do a search for” on a table with a constraint to pull out products where the product owner is the logged in user. I’m not sure if that fits the bill for a “custom datatype” - I suspect not but my thinking is a bit cloudy…
I’ve been called away for the rest of the day so must dash but I’ll have a look into this on Monday but I really appreciate your input. Thank you.
All the best
Joe
A custom datatype is a datatype you’ve created in the data tab of your app… (a database table)
A dropdown (or any other element) can have a content-type which is a custom datatype, or it can have a content-type which is system type (such as text, number, date, image etc.)… or it can have a type which is an Option Set… or an API data call type…
But if you’re doing a database search then it must be a custom datatype, so that answers that question…
But as you have things set up, you’ll probably need to do 2 searches (1 to find the ‘Add New’ item, and the other to find the current User’s items) and merge them…
If you used Privacy rules instead of a search constraint, you could do it all with a single search.
Again, I’m in awe of your knowledge. Thank you ever so much for sharing it. You’ve enabled me to achieve what I needed to do and now I can go out to play early!
After adding a new location in the pop up, how do you trigger the dropdown to update and present the newly created item?
I couldn`t find a way, so eventually i just added a button to start the flow, save the new item in a custom state, and use the custom state to change the dropdown default value.
The way I did mine, and it seems a little clunky now having read Adam’s solution above (see post #3 in this thread)…was to…
- Create a Drop Down List showing products/locations/whatever on a PopUp and put “Add New” as the first entry in that PopUp.
- Create a Workflow that runs when the DropDown in step 1’s value is changed and the value of the DropDown is “Add New” which opens a second popup where a User inputs a new item (in your case, a location).
- Put a “Close” button (or “Exit” or “Save” or “Whatever”) on that popup and when it’s clicked, reopen the previous PopUp. This will cause the list to refresh.
Hope that helps. Good luck.
Once you add a new item, it will automatically appear in the drop-down list.
So no need to do anything.
Appear yes, but the “Add New” is “selected”, while i would like the new added item “selected”