-
4 Aug 2011 6:01 AM #1
Adding items to a select field dynamically
Adding items to a select field dynamically
Hi,
Scenario
I have a select field with predefined items. When I choose an item from the list a new item should be added to the list. If I could clone the selected item somehow and just change the value attribute that would work.
Problem
I have successfully managed to add items dynamically as described above. The problem is that they are not "valid" items. Looking at the predefined items in Chrome I can see "c"-objects, or whatever they are (components?), with data, events and everything. When I add items using either setOptions or adding to the store they just show up as regular objects, no events. This causes problems later when I need to fetch values/change the items.
Anyone have a solution for this? Yes, I have searched for answers, but haven't found anything.
Thanks.
-
5 Aug 2011 6:43 PM #2
can you call myselectfield.setOptions( ???
-
11 Aug 2011 6:40 AM #3
Yes, but that does not work as I want it to. As I described in my post, the new items are not the same as the predefined ones. They are missing event handlers and a bunch of other stuff.
Am I missing a magic select.update() call of some kind?
-
11 Aug 2011 9:21 AM #4
How to you set up your new options? Is it a JSON object? (i.e. {text: 'displayvalue', value: '0'} )
And,
does your selectfield have a listener for the 'change' event?
-
12 Aug 2011 1:47 AM #5
Here's the code I'm using:
Code:xtype: "selectfield", id: "bla", name: "blabla", label: "Label", options: data, <-- array with {text, value} entries listeners: { change: function (field, value) { field.setOptions([{ value: "newvalue", text: "My new value" }], true); } } }Last edited by dannilsson; 12 Aug 2011 at 1:47 AM. Reason: Fixed code
-
18 Mar 2013 7:35 PM #6


Reply With Quote