Advanced Dropdown Question

Hello,

Is there any way to perform formatting on a particular row in a dropdown menu?

I have a data type named Subcategories which includes both Category and Subcategory (Category is repeated for each row). I am using a dropdown menu to display all unique categories using :Unique Element which then filters a repeating group which lists out all subcategories for the category selected. The user is expected to review and/or edit and mark the subcategory as “reviewed”, which is another field within the same thing.

What I am having trouble doing is identifying within the dropdown menu which Categories have no more Subcategories requiring approval. I am looking to either:

  1. Have two partitioned lists within the dropdown so I can group Categories with Subcategories still to be reviewed from those completed.
  2. BOLD the font of Categories that still have Subcategories that require review.
  3. List a count of the number of remaining Subcategories per Category in parenthesis next to each Category (ie. Category (2)).

I know this can be done using a repeating group instead of a dropdown menu but for a few reasons, prefer to do this in a dropdown menu if possible. I also can easily display a list box of remaining subcategories and user continues until empty but a bit of a real estate issue.

All the data is in one data type. There is a row for every Subcategory. A list of unique Categories is obtained by using :Unique Elements.

Thanks in advance for anybody who has some ideas.

Keith

2 Likes

Hi @ktobias,

Here’s something that you can do to group the dropdown items into reviewed and not reviewed as you mentioned in #1.

Start with sorting your dropdown by reviewed:

And then add some javascript that adds a couple disabled options as pseudo groups:

You could also do actual optgroup’s for true grouping in the select, but that’s more involved as you need to add the options as children. With the disabled options, it looks about the same, just not indented. Note, the “(reviewed yes/no)” text is just my label for testing.

05%20PM

This is all something I threw together, not something I pulled from existing production stuff, so make sure to test all the possibilities. You might also have to place something to refresh the dropdown if the reviewed status can change. Maybe some of our more experienced javascript folks can jump in with something more elegant!



Looking to improve your Bubble™ skills?

Let me turn
:thinking: :tired_face: :confounded:

into
:grinning: :sunglasses: :woman_student:

Coaching and Development at https://uniqueideas.com or schedule a free intro session :gift:

Ken Truesdale
LinkedIn

5 Likes

Nifty idea, @mebeingken! Love your helpful and creative suggestions here in the forums.

To the OP: This sounds to me like a dropdown is a lousy interface for something so complex. Why not create a better interface? If you have a lot of meta-info to display about a thing that someone needs to make a decision about whether they should spend time reviewing it, why not help them make that decision? (Like, how long has it been waiting for review? Also, your description here is so overly-general that its hard to make a clever suggestion. Tell us what you’re trying to accomplish, but also show us what you’ve got so far. Screenshots are helpful.)

You’ve got pretty much unlimited flexibility to improve on dropdowns with repeating groups, so I’d encourage you to think outside of the dropdown in this case, @ktobias. Also, keep in mind how dropdowns appear on mobile. Ick.

Thank you so much @mebeingken for the solution. The end result is exactly what I am looking for. Wouldnt have figured this on my own as not familiar with adding javascript actions. Will give it a shot.

@keith I am with you somewhat. I have limited space to work with and the function of the dropdown menu fits very well. I do not have a lot to display, just the need to append the reviewed status along with the subcategory name. While intrigued by some of the comments about aging etc., and could have used that on some other apps I have worked on, overkill for this application.

I appreciate both responses. These Bubble forums rock! Happy New Year all!

Best,

Keith

2 Likes

Gotcha. Note that you can use conditional text (boolean-expression:formatted as text) to indicate all sorts of things in dropdown menu items, just as you can anywhere in Bubble). Like you could adopt an “unread message” type metaphor with a bullet, emoji or other special character to indicate unseen/unreviewed items.

Nope @keith, that is news to me as well! I have a lot to learn. LOVE the platform. Thank for again for the suggestion.

K

Hey @keith. Can you tell me more about this. I had no idea.

@mebeingken, again thank you for your suggestion. To get familiar with what you proposed, I created a small example so I could replicate your code as easiest for me to digest by reverse-engineering. However, seem to be missing something as my dropdown displays subcategories with none of the elements from the javascript. I copied basically verbatim except changed name of dropdown from my_dropdown to mydrop. Any suggestion on what I am missing?

Thanks,

Keith T.

One thing not shown in the screenshot is that you need to give the dropdown element an id – this is what my_dropdown references in the js. So on your dropdown, now that you have changed to mydrop, make sure it has an ID attribute (bottom of properties) of mydrop. If you’ve already set that, post up some screenshots and I’d be happy to take a look.

While I could post some pix later, I’m mobile at the moment. Easiest to just try it for yourself:

  1. In any expression field, write a boolean (yes/no) expression. (E.g., Current User’s First Name is “Keith”)

  2. In run mode this will by default render “yes” for true and “no” for false, right?

  3. Note that you can customize the return values by adding the :formatted as operator. Do that.

  4. You’ll see a dialog that lets you customize yes and no. (So in my example, turn yes into “Hi, Keith!” And turn no into, “Hey, you’re not Keith! You’re” Current User’s First Name.

So, you see, conditions can be infinitely nested…

Thank you again! Once I added in ID’s through Settings, and adjusted ID to match, it ran as expected. I see how it works and will play around. Thank you for your help.

1 Like

And here ya go: In case it wasn’t obvious what I’m talking about (though it should be). Here’s a dropdown with dynamic values where we are designing the Option Caption. As in any text expression box (the contents of a text element would be another example), we can write all sorts of interesting expressions and render their results as text. Have a look:

Our choices here are sourced from an API call (to Rebrand.ly). This call returns a bunch of info about one’s Rebrandly domains. Let’s imagine that we want to select one of the domains for whatever reason.

The Option caption field could be boring of course and just give us the name of the domain. That would be the first part here:

  • Current option's fullname: This expression returns the value stored in the “fullname” field that the API call returns. It’s just the name of the domain, formatted like “go.grupz.com”.

But we can display other useful info as well. In total, there are 4 expressions here (the one I describe above, followed by a text pipe character [that’s just text that I typed], followed by 3 more expressions). The remaining three are these:

  1. Current option's https:formatted as text: What is this? Well, “https” is a boolean value (what Bubble calls a yes/no value) that represents whether the domain in question supports https. So writing: “Current option’s https” will, by default, return one of two strings (text values): It will return “yes” if https is yes/true and “no” if https is no/false.

So we’d get a menu item that looks like: “go.grupz.com | yes”

This wouldn’t be super-helpful would it? That’s why we add the “:formatted as text” operator. This lets us control how “yes” and “no” values are presented. So for example, we could render “yes” as “HTTPS Active” and we could render “no” as “HTTPS not supported”.

Again, that’s overly verbose for a dropdown menu, so perhaps we’d just throw up an emoji like the lock icon. And that’s what I did here.

Drilling down into the expression (clicking the “:formatted as text” part), we see:

And you can see that I render “http is yes” as the lock emoji followed by a space and a pipe character.

For “http is no” I left the field blank (so it’s the return value is just going to be null, nothing, empty, nada, zilch, zip… it won’t take up any space).

Moving on, there are two more expressions like this – both of them are boolean expressions followed by the “formatted as text” operator:

  1. Current option's active:formatted as text: This is just like example 1. And what i did is just return thumbs up emoji for yes and thumbs down emoji for no.

  1. Current option's type is "USER":formatted as text: This is a little more interesting. The “type” value returned from this API is a string with various values. If the domain is a user-created one, it has the value “USER”. If the domain is a built-in one, it has the value “SYSTEM”. There may be other values as well. (Who knows? Not me. Who cares? Not us… this is just an example.)

Now, a string (“text” in Bubble parlance) isn’t a boolean value of course. But a text can be used in a boolean expression. The expression Current option's type is "USER" evaluates to a boolean value. (Duh, right? The string object type contains some string value. If that value is “USER”, this expression will evaluate to yes. If that value is anything other than “USER”, this expression will evaluate to no.)

So now we have another yes/no thing that we can reformat to our liking using :formatted as text.

HERE’S THE INTERESTING PART: You can nest :formatted as text operators inside of these Boolean Formatting dialogs. So we can do this:

Now, if type has the value “USER”, we are going to print out the “user”/“silhouette” emoji. If type DOES NOT contain “USER”, we are going to evaluate YET ANOTHER condition:

Current option's type is "SERVICE"

… and by appending the :formatted as text operator, I have access to yet another Boolean Formatting dialog. By clicking here (red circle):

… we get a place where we can define what should happen if type is “SERVICE” and also what should happen if type IS NOT “SERVICE”:

… and you can see that we will return the gear emoji for “SERVICE” and the big red question mark emoji is the value isn’t “SERVICE”. We could have just as easily chosen to return some other text expression, like Current option's type (that is, if the type is neither USER nor SERVICE, just print out the value itself). Further, I could have gone deeper down the rabbit hole and evaluated for other known values of type, but I think you get the idea.

What all of this does is as follows: In run mode, here’s how my dropdown options look:

image

We see the domain name, an icon indicating whether the domain supports https (all of them do), an icon indicating whether the domain is active (all of them are), and what type of domain this is (2 “user” domains, 1 “service” domain).

This is just an example. And again, this technique is not specific to dropdown options. You can (and should) use this type of expression evaluation in any expression field where you can put a text.

7 Likes

@keith! This is awesome. I had no idea. I have already incorporated this idea into my app. Thanks for the very detailed explanation. I’m sure it will be helpful to other Bubblers who come across this thread.

1 Like

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