$select widget with multiple selections

106 views
Skip to first unread message

Matthew Lauber

unread,
Nov 4, 2015, 1:15:07 PM11/4/15
to TiddlyWiki
I'd like to have a select widget that uses the multiple property of the base html select widget, and when selected, updates a list field with all the selected values.  Is this something someone has seen/done before, or am I in new territory?

Thanks,
Matt

Jed Carty

unread,
Nov 4, 2015, 3:16:39 PM11/4/15
to TiddlyWiki
The only discussion about changes to the widgets I have seen is about letting them trigger action widgets so you may be in new territory. This is related to the various list manipulation experiments going on. Mine is here and the work by Matabele is here. Neither of these will do what you want, but that is the current state of work related to what you are asking. It may be a good idea to wait until we figure out how to do the arbitrary list manipulations (or help out!) before updating the select widget like that because it would use some of the same things on the backend.

Matthew Lauber

unread,
Nov 4, 2015, 3:51:33 PM11/4/15
to tiddl...@googlegroups.com
I've actually got a backwards compatible fix for this (using a new keyword "multiple" to enable the new behavior) that I can publish here in a bit.  I'm working on cleaning up the code now, but I can throw a gist up.  https://gist.github.com/mklauber/4011a7ea95b158bfcfbf  I actually don't think I need your listops functionality, because for my purposes, the select widget is the system of record, and I can just set the field text to the selected values in the field.  

Edit: Just to clarify, while I've got a working fix, it's not done yet.  There's some cleanup to do, and I still need to decide how I want to handle styling the size of the multiple select.  

Eric Shulman

unread,
Nov 4, 2015, 4:05:05 PM11/4/15
to TiddlyWiki
On Wednesday, November 4, 2015 at 10:15:07 AM UTC-8, Matthew Lauber wrote:
I'd like to have a select widget that uses the multiple property of the base html select widget, and when selected, updates a list field with all the selected values.  Is this something someone has seen/done before, or am I in new territory?

The $select widget doesn't currently support the "multiple" property.

To make it capable of handling multiple values, there are two functions in $:/core/modules/widgets/select.js that need to be extended:

* SelectWidget.prototype.handleChangeEvent() currently just assigns the DOM element's .value attribute (the "current selection") to the target tiddler field/index.   To support multi-select, this function needs to iterate over all the items in the DOM element's .options array and concatenate all the selected items into a single space-separated, bracketed list that it can then write into the target tiddler field/index.

* SelectWidget.prototype.setSelectValue() currently just takes the stored value from the tiddler field/index, and sets it into the DOM element's .value attribute.  To support multi-select, this function needs to split a space-separated, bracketed value stored in the tiddler field/index into separate items that can then be individually selected in the DOM element.

Both of these enhancements would only be triggered when the "multiple" attribute is used in the <$select> widget, so that the widget behavior would be unchanged for all current uses, so this would be a 100% backward-compatible improvement to the core functionality.

-e

Matthew Lauber

unread,
Nov 5, 2015, 8:58:36 AM11/5/15
to TiddlyWiki
@Eric, see my gist at https://gist.github.com/mklauber/4011a7ea95b158bfcfbf . I've actually got a version of this working, though I'm still fixing bugs, most notably a tiddlywiki script crash if the destination tiddler doesn't exist.  Once I've got enough of the bugs resolved with my own usage, I'll open a PR.

Tobias Beer

unread,
Nov 5, 2015, 3:50:53 PM11/5/15
to TiddlyWiki
 Hi Matthew,

gist at https://gist.github.com/mklauber/4011a7ea95b158bfcfbf . I've actually got a version of this working, though I'm still fixing bugs, most notably a tiddlywiki script crash if the destination tiddler doesn't exist.  Once I've got enough of the bugs resolved with my own usage, I'll open a PR.

Cool stuff, and useful in promoting list-fields more, not meaning the list field, mind you.

Tobias.
Reply all
Reply to author
Forward
0 new messages