PDA

View Full Version : How to select a just-added ComboBox item



johnholden
25 Jan 2011, 12:34 PM
Hello,

I have implemented a ComboBox (var combo, below) where I allow users to freely type in values that may or may not exist (using forceSelection = "false"). After they type a non-existent value, a dialog window opens and prompts the user to enter more details about this new Record (var rec, below). The new record is saved to the store (which uses JsonWriter), I attempt to select the new record in the combo and the window is closed.

The only complication is that I want to automatically select the new Record from the ComboBox, but I can't seem to make it actually select the record. Of course it still shows the display text in the combo, just not the actual selected record. I can load pre-selected values initially by calling setValue() on the ComboBox, but in this case I do not have an ID to select using setValue(). I have tried calling:


combo.view.select(rec);

but this does not seem to select the actual record. In a desperate attempt, I even tried working out the record's index in the store using these methods attached to the store itself:


_findByRecordFilter: function(rec, id) {
return (rec == this.findMe);
},
findByRecord: function(r) {
return this.findBy(this._findByRecordFilter, {findMe: r}, 0);
}

but alas did not work either. It always finds that index 0 contains the record, and fails to select it (or for that matter fails to select what is really at index 0).

I considered registering an event handler on the store to update the combo when its store is updated, but then I'd need to unregister the handler as well and it just seemed way too messy to be right. Surely someone must have done this before?

Thanks in advance for any help! I'm going crazy here!

John