Custom dropdown with checkboxes


#1

Hi everyone!

We put together an example of a custom dropdown with custom checkbox items:

As you may know, there’s already a custom checkbox and a custom dropdown widget included in the Axure Training Library. We also have a couple tutorials here and here. Meanwhile, we also saw some examples where it was useful to combine the two elements, and so we put together a file below:

CustomCheckboxDropdown.rp (111.2 KB) | See it live!

Read on to learn more about the interactions.



**The OnSelected Event**

This screenshot shows how we dynamically add text to the target shape via the Set Text action each time a checkbox item is clicked and set to selected:

For Case 1, if there is no text on the target shape, then the interaction will fire and simply add the text of the clicked item onto the target shape.

For Case 2, on the other hand, if there is already text on the target shape, then this interaction will fire and we’ll effectively create a comma-separated list. This interaction sets the existing text on the target shape, affixes a comma & space (", ") behind it, and then adds the text from the clicked item.


The OnUnselected Event

After an item is selected and its text is added to the target shape, we’ll also want to create the opposite interaction so as to remove the text when an item is deselected. The OnUnselected case is where we determine the portion of text to remove, and we use compound string functions to do that.

(Note: if you’re unfamiliar with using the JavaScript string functions substring() and indexOf(), or with using string functions in the tool in general, check out the linked articles for reference.)


Here's its **Set Text** action in full:
[[target.text.substring(0,target.text.indexOf(this.text))]][[target.text.substring(target.text.indexOf(this.text)+this.text.length+2)]]

The substring() expression in the first set of double-brackets serves as a way to specify the substring in front of the deselected text. It takes the value of target.text (i.e. the text on TargetShape) and returns a portion of the string between a numerically-defined start point and end point. In this part of the function, we’ll enter 0 (zero) for the start point and enter target.text.indexOf(this.text) for the end point. This returns the text of existing list options that’ve been selected and are positioned in front of the deselected text:


The substring() expression in the second set of double-brackets serves as a way to specify the substring behind the deselected text. That is, it returns the text from the index position of where the deselected text is found all the way to the end of the entire string (+1 to accommodate the extra space between list options on the TargetShape widget):


Last, the Fire Event action triggers the TargetShape’s OnMove conditional case, which looks like this:

[quote]If [[This.text.substr(-2)]] equals value ", "
   - Set Text on this equal to [[Target.text.substring(0,target.text.length-2)]][/quote]

This action trims any extra comma and space that’s left over at the end of the string, if the last two characters are indeed a comma and space (", ") per the condition.


I hope some of you find this useful! Drop a line if you have followup questions or shoot us an email at support@axure.com.

Alex


Multi-select dropdown
Custom dropdown with checkboxes with condition
Multiple Search Selection dropdown
#2

I have made something similar but now trying to include ellipses to handle overflow text. I also want to prevent line wrapping or at least limit it to 2 rows. Any ideas on how best to achieve this?


#3

Hi uiguyjohn,

Hmm, would you be able to post your RP file here so that I could take a closer look at the setup of your interactions/widgets? That’ll allow me to provide some more targeted assistance. Ty!


#4

Hi Alex,
I really like this sample. Is it possible to create the same widget by using only LVAR?
CustomCheckboxDropdown-LVAR.rp (324.1 KB)

Thank you in advance!
Natalie


#5

Hi Natalie,

Hmm, I’m a little confused about what you’re asking. In Alex’s example file, he’s using Axure’s native [[this]] and [[target]] properties to build the interactions. While you can certainly use local variables instead of [[this]] and [[target]], e.g. LVAR, [[this]] and [[target]] automates this process so you do not have to reference the selected or targeted widget in the interaction. That is, [[this]] will automatically reference the widget that is selected/“doing” the interaction and [[target]] will automatically reference the widget that is being targeted in the interaction.

Lmk if you have any questions, or if I misunderstood!


#6

Hi Jane,
Thank you for quick reply! My question, how to avoid use of Global variables for this widget.


#7

Hi Natalie,

No problem! Actually, it doesn’t look like Alex’s example file has a need for those global variables, as any changes I make on either of the pages, “Styled Checkboxes” or “Standard Checkboxes”, doesn’t update or use the global variable values (I used the Console tab in the HTML sidebar to check this). As such, feel free to remove the four global variables as it doesn’t look like they’re needed for the interactions to work.


#8

Thank you, Jane! I will follow your advice!
Regards,
Natalie


unlisted #9

closed #10