PDA

View Full Version : Combo item not in store result



john76543
12 Oct 2013, 1:26 AM
I've got a combo that queries a remote store. Sometimes the currently selected item isn't in the store's result set. The combo list just sticks the old item on the end.

Is there any way to change this behaviour, so the combo list ONLY shows items returned from the store, and forgets the current item if it's not included?

Thanks,

Ext 4.2.1

john76543
14 Oct 2013, 10:15 AM
Here's my fix. combo.onLoad calls setValue() for the current items, which has the effect of adding them if they're not in the store. So I just override onload to detect missing items, let Ext add them, and then set an 'invalid' flag that my app can use for special rendering.

Clearly this isn't a generic solution, but I hope it proves helpful.



onLoad: function (store, records, success)
{
var me = this;


if (me.ignoreSelection > 0)
{
--me.ignoreSelection;
}


if (success && !store.lastOptions.rawQuery)
{
if (me.value == null)
{
if (me.store.getCount())
{
me.doAutoSelect();
} else
{
me.setValue(me.value);
}
} else
{
// identify selected items missing from store
var missing = [], i, found;
if (!Ext.isEmpty(me.value))
{
var current = Ext.Array.from(me.value);
for (i = 0; i < current.length; ++i)
{
found = store.getById(current[i]);
if (found === null && !Ext.isEmpty(current[i]))
missing.push(current[i]);
}
}


me.setValue(me.value);
for (i = 0; i < missing.length; ++i)
{
// any missing tags, mark them as 'invalid' so they render in red
found = store.getById(missing[i]);
if (found)
found.set("invalid", true); // In my app, this causes a special red style to be used
}
}
}
}

Gary Schlosberg
14 Oct 2013, 11:36 AM
Glad you found a solution, and thanks for taking the time to post a follow-up.