PDA

View Full Version : [CLOSED] Set Combo Box selected item on page load



registrator
Mar 24, 2015, 8:50 AM
For my combo box


X.ComboBoxFor(m => m.TYPE).ID("ComboBoxType").MultiSelect(false).LabelWidth(50).Width(150).Edi table(false).Items(new ListItem("Invoice", "INV"), new ListItem("Pro-Forma", "PRO")).SelectedItems(X.ListItem().Value("INV")),

I would like to select the first item on opening the window where the combo box is.


Ext.onReady(function() {
var combo = Ext.getCmp('ComboBoxType');
combo.setValue('INV');
});

I keep getting


Uncaught TypeError: Cannot read property 'setValue' of undefined

What am I doing wrong please?

Daniil
Mar 24, 2015, 10:29 AM
Hi @registrator,

A ComboBox is not rendered yet when the onReady handler is executed.

Please clarify does SelectedItems not work for you? You should be able to set up a selected item's index as well.

registrator
Mar 27, 2015, 9:33 AM
Hi Daniil

Select Index does not work for me. For some reason it is turning my combo into MultiSelect version that I cannot turn off.
So I was thinking of setting the selected item when the page loads.
If this is not a correct event, can you suggest some other event please?

Thank you

Daniil
Mar 27, 2015, 9:48 AM
You can try with a ComboBox's AfterRender event.

Though, I would really prefer to find out what is going wrong with SelectedItems. But I need a test case to reproduce.

registrator
Mar 27, 2015, 10:02 AM
I would love to figure out why is the combo behaving like it is but I cannot reproduce this anywhere else but my solution.
And I have spent so much time on it that I cannot afford to lose more. I just want to figure out a way to make it work no matter how dirty it is.

Daniil
Mar 27, 2015, 11:07 AM
I cannot reproduce this anywhere else but my solution

Is there a possibility to share the test page online and publicly?


I just want to figure out a way to make it work no matter how dirty it is.

Does the AfterRender event help?

registrator
Mar 27, 2015, 12:22 PM
I can actually deploy this on line to show you.
Can I please send you the login credentials in a private message?

registrator
Mar 27, 2015, 12:42 PM
I have managed to fix it with the AfterRender!!! Burden off my back.

Thank you

Daniil
Mar 27, 2015, 3:00 PM
Can I please send you the login credentials in a private message?

Sorry, we can deal with something that is accessible publicly. Never mind if you were able to sort out the problem.