PDA

View Full Version : How to update combo's editable property at runtime?



ronnieoverby
11 Oct 2010, 7:22 AM
I am using the ExtAspNet library. For some reason it doesn't let me make editable comboboxes directly. So, I am trying to make the combobox editable at runtime by doing this:


Ext.onReady(function () {
var timeCombo = Ext.getCmp("MainContentPlaceHolder_winEditWorkshop_ddlTime"); // need to find more reliable way to find the component, but this works for now
timeCombo.setEditable(true);
});

This will now let me type into the combobox, but when I change focus, the input disappears. How can I retain the user input, so that it will submit with the form?

ronnieoverby
11 Oct 2010, 7:30 AM
Figured it out. The API docs helped me find the property I needed to set:


Ext.onReady(function () {
var timeCombo = Ext.getCmp("MainContentPlaceHolder_winEditWorkshop_ddlTime");
timeCombo.setEditable(true);
timeCombo.forceSelection = false;
});

Condor
11 Oct 2010, 7:33 AM
How is the combobox configured (valueField, forceSelection etc.)?

ronnieoverby
11 Oct 2010, 7:34 AM
Spoke too soon. I can't select any of the predefined items from the list. When I try, it selects the first list item.

Condor
11 Oct 2010, 7:35 AM
That probably means that it's configured with an invalid valueValue.

ronnieoverby
11 Oct 2010, 7:43 AM
I'm sorry, but I don't follow. I have the object open in firebug and the value of value is "".

Condor
11 Oct 2010, 7:48 AM
ExtAspNet generates .js code, doesn't it? Could you post the code generated for MainContentPlaceHolder_winEditWorkshop_ddlTime?

ronnieoverby
11 Oct 2010, 7:55 AM
http://pastebin.com/1fdZE15E or:


var x5 = new Ext.form.ComboBox({
x_state: {
"X_Items": [
["", "6:00 AM", 1],
["", "6:30 AM", 1],
["", "7:00 AM", 1],
["", "7:30 AM", 1],
["", "8:00 AM", 1],
["", "8:30 AM", 1],
["", "9:00 AM", 1],
["", "9:30 AM", 1],
["", "10:00 AM", 1],
["", "10:30 AM", 1],
["", "11:00 AM", 1],
["", "11:30 AM", 1],
["", "12:00 PM", 1],
["", "12:30 PM", 1],
["", "1:00 PM", 1],
["", "1:30 PM", 1],
["", "2:00 PM", 1],
["", "2:30 PM", 1],
["", "3:00 PM", 1],
["", "3:30 PM", 1],
["", "4:00 PM", 1],
["", "4:30 PM", 1],
["", "5:00 PM", 1],
["", "5:30 PM", 1],
["", "6:00 PM", 1],
["", "6:30 PM", 1],
["", "7:00 PM", 1],
["", "7:30 PM", 1],
["", "8:00 PM", 1],
["", "8:30 PM", 1],
["", "9:00 PM", 1],
["", "9:30 PM", 1],
["", "10:00 PM", 1]
],
"SelectedValue": ""
},
id: "MainContentPlaceHolder_winEditWorkshop_ddlTime",
hideLabel: false,
fieldLabel: "Time",
anchor: "-25px",
name: "ctl00$MainContentPlaceHolder$winEditWorkshop$ddlTime",
enableKeyEvents: true,
hiddenName: "ctl00$MainContentPlaceHolder$winEditWorkshop$ddlTime",
store: new Ext.data.ArrayStore({
fields: ['value', 'text', 'enabled', 'prefix']
}),
listeners: {
beforeselect: function (cmp, record, index) {
if (!record.data.enabled) {
return false;
}
},
render: function (cmp) {
cmp.x_loadData();
cmp.x_setValue();
}
}
});

Condor
11 Oct 2010, 8:00 AM
I don't use ExtAspNet, so I don't know what x_loadData() and x_setValue() do, but I can guess...

This creates a text/value type combobox, but all values are "". Any way to create a text type combobox (name instead of hiddenName - no value, only text)?

ronnieoverby
11 Oct 2010, 8:06 AM
I have managed to get it to include the values in the array. Still having problem, though:

http://pastebin.com/R2XViH2h (all generated javascript).

Condor
11 Oct 2010, 8:08 AM
Now you should be able to edit the text, but only to one of the entries in the combobox.

If you really want to allow any input then this combobox definition isn't useful.

ronnieoverby
11 Oct 2010, 8:10 AM
That is correct. I can enter text, but it doesn't submit for some reason. Can I alter the combobox at runtime to allow this? What would be an example of a useful combobox definition?