Ticket #6022 (new enhancement)

Opened 9 months ago

Last modified 22 hours ago

ComboBox: set value programatically according to item from store

Reported by: wolfram Owned by: wolfram
Priority: normal Milestone: 1.4
Component: Dijit Version: 1.0
Severity: normal Keywords:
Cc: bill, alex

Description (last modified by alex) (diff)

Add ability for ComboBox.setValue() to take an item, in which case it will set ComboBox.item = item (just like when you select something from the drop down list), and display the item's value in the <input>.

Sort of implicit in this patch is the idea that ComboBox.item should be set whenver there is an item corresponding to what the user typed in.

Attachments

patch6022.diff (0.7 kB) - added by wolfram 9 months ago.

Change History

  Changed 9 months ago by dylan

  • milestone set to 1.2

  Changed 9 months ago by bill

  • status changed from new to closed
  • resolution set to wontfix

No, there isn't any builtin way to make ComboBox automatically select a value, and no plans to add it; I'd suggest posting to the dijit support forum. Certainly you should be attaching to some method in ComboBox? (called when the data from the store is returned) rather than using a timer.

Changed 9 months ago by wolfram

  Changed 9 months ago by wolfram

  • status changed from closed to reopened
  • resolution deleted

The attached patch allows for a simple and clean way to set a value that actually comes from a store. May be a more integrated way is possible, but that one looks like a very flexible one. The patch actually just allows to call setValue() using an item from a store. And it makes only sense using an item from the widget's store. Like so:

>>> w = dijit.byId("myComboBox")
>>> w.store.fetch({query:{name:"whatever*"}, onComplete:function(items){ w.setValue(items[0]) }})

This example just uses the store of the combobox, retreives the item we need (actually it might be a number of items, but items[0] is only used). And we just stick this item into setValue() which (after applying the patch) sets the value properly using the item.

The advantages are:

  • setting a value form an item is possible
  • the combobox internals are not required to know
  • you can fire any kind of search against the store and still preprocess the items before calling setValue()
  • its relatively simple :-)

hope this can convince bill :-)

follow-up: ↓ 8   Changed 9 months ago by bill

  • type changed from defect to enhancement
  • description modified (diff)
  • summary changed from ComboBox: Select an option coming from a store programmatically to ComboBox: set value programatically according to item from store

Perhaps we could add this feature; couple things for me to think about though. Basically, ComboBox.item isn't meant to be accessed by the developer since sometimes it's null (like when the user has typed a random value into the input). Never meant to support this and not sure if I want to, but this patch sort-of implies that we are doing that. Not sure if I want to expand the API to support that although I can see some value. Need to check:

  • if the user types in a value equal to something in the drop down list, but doesn't actually select the value from the drop down list nor uses auto complete, check if ComboBox.item gets set.
  • need to test if patch works for FilteringSelect

  Changed 8 months ago by freelock

I opened #6197 before finding this issue, and I think it's related. In an application I'm developing, being able to access ComboBox?.item is very useful, and it's trivial to check for it being null before passing it to the store.

Obviously, I think this is a useful part to the api, and assumed it would be there since it wasn't marked private...

  Changed 7 months ago by alex

  • cc bill added
  • description modified (diff)

where are we on this? bill?

  Changed 7 months ago by alex

  • cc alex added

in reply to: ↑ 4   Changed 7 months ago by wolfram

Replying to bill:

Perhaps we could add this feature; couple things for me to think about though. Basically, ComboBox.item isn't meant to be accessed by the developer since sometimes it's null (like when the user has typed a random value into the input). Never meant to support this and not sure if I want to, but this patch sort-of implies that we are doing that. Not sure if I want to expand the API to support that although I can see some value. Need to check: - if the user types in a value equal to something in the drop down list, but doesn't actually select the value from the drop down list nor uses auto complete, check if ComboBox.item gets set. - need to test if patch works for FilteringSelect

I added the .item property and it is not private to be possible to read from outside! That is intentionally, because when the data come from a store it makes a loooot of sense to be able to access the item who's value is the one you have selected in the combobox. And since an item can contain more data than just the displayed value you need access to the item. And that it can be null is part of the contract! I.e.

var id = widget.store.getValue(widget.item, "id");
var firstName = widget.store.getValue(widget.item, "firstName");
var lastName = widget.store.getValue(widget.item, "lastName");

You can access a looot of data through the item, if the backend sends them along. But the combobox normally only shows one piece of those data, i.e. the "username" (would make sense with the above exacmple code).

I am very much for making the .item a first class citizien, since the dojo.data API is an important part for dojo and combining it with the combobox makes the combobox even stronger.

  Changed 6 months ago by bill

Ok, that sounds good, Wolfram can you prepare a patch that does that? I looked at test_ComboBox.html and by calling dijit.byId("setvaluetest").item from firebug at various times I noticed that

  • when the widget is originally displayed item is null (it should be set to something)
  • selecting California from the drop down list correctly sets item
  • typing in California and then hitting the tab key... item is null (it should be set to something)

  Changed 6 months ago by wolfram

  • owner set to wolfram
  • status changed from reopened to new

I will fix it. Meanwhile there is a nice example that shows the behaviour in real time http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/data/demos/demo_QueryReadStore_ComboBox.html (Watch out latest WebKit? seems to have an issue with the arrow-down key ... just noticed)

That the item is initially set to null is correct! There is no item selected, so what should it be set to? null is intended, since it means something like nothing, nix, nada ... or what would be your expectation here Bill?

Actually the last thing you mentioned might be something to handle additionally "typing in California and then hitting the tab key... item is null (it should be set to something)". So I would add this to the patch, otherwise its there.

  Changed 3 months ago by bill

  • milestone changed from 1.2 to 1.3

bump enhancements to next milestone, as we prepare to close out 1.2

  Changed 22 hours ago by bill

  • milestone changed from 1.3 to 1.4

bumping 1.4 tickets to 1.5, and most 1.3 tickets to 1.4

Note: See TracTickets for help on using tickets.