PDA

View Full Version : [OPEN] [#136] ComboBox ForceSelection problem



FpNetWorth
Jan 24, 2013, 10:15 AM
Hi all,

I have a problem when loading a combobox.
The problem is that when I use the ForceSelection="true", the value does not load into the combo.
When removing the ForceSelection="true", the value appears in the combo

Please find below a sample


<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<title>Ajax Linked Combos - Ext.NET Examples</title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
object[] typeOfActivitiesList = new object[]
{
new object[] { 1, "type1" },
new object[] { 2, "type2" },
new object[] { 3, "type3" },
new object[] { 4, "type4" },
new object[] { 5, "type5" }
};
this.storeTypeOfActivity.DataSource = typeOfActivitiesList;
this.storeTypeOfActivity.DataBind();
this.ComboBox1.Value = 1;
this.ComboBox2.Value = 1;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<ext:ResourceManager ID="ResourceManager1" runat="server">
</ext:ResourceManager>
<ext:Store ID="storeTypeOfActivity" runat="server">
<Model>
<ext:Model ID="modelTypeOfActivity" runat="server">
<Fields>
<ext:ModelField Name="getId" Type="Int" />
<ext:ModelField Name="getName" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
<ext:ComboBox LabelWidth="200" runat="server" ID="ComboBox1" Width="300" FieldLabel="Combo 1 ( ForceSelection=false)"
LabelAlign="Right" LabelSeparator=" " AllowBlank="false" DisplayField="getName"
ValueField="getId" StoreID="storeTypeOfActivity" QueryMode="Local" MatchFieldWidth="false">
</ext:ComboBox>
<ext:ComboBox LabelWidth="200" runat="server" ID="ComboBox2" Width="300" FieldLabel="Combo 1 ( ForceSelection=true)"
LabelAlign="Right" LabelSeparator=" " AllowBlank="false" DisplayField="getName"
ValueField="getId" StoreID="storeTypeOfActivity" QueryMode="Local" MatchFieldWidth="false"
ForceSelection="true">
</ext:ComboBox>
</div>
</form>
</body>
</html>




Any help is appreciated,
Thanks.

Daniil
Jan 24, 2013, 12:27 PM
Hi @FpNetWorth,

It looks a bug. I reported to Sencha.
http://www.sencha.com/forum/showthread.php?254742

For now, I can suggest to try to set up an initial value if the Store's Load event.

Daniil
Jan 24, 2013, 3:46 PM
Sencha opened a bug.

We created an Issue to track.
https://github.com/extnet/Ext.NET/issues/136

FpNetWorth
Jan 24, 2013, 5:20 PM
Sencha opened a bug.

We created an Issue to track.
https://github.com/extnet/Ext.NET/issues/136

Thank you Daniil for your efforts,
Hope that it will be fixed soon!

ltctech
Jan 29, 2013, 2:33 AM
Hi,

I have the exact same issue, though I think I have found an easy workaround for the time being.
Just remove ForceSelection from ComboBox and stick it into AfterRender listener.
Seems to populate my value I set in Page_Load and ForceSelection still works.



<Listeners>
<AfterRender Handler="this.forceSelection = true;" />
</Listeners>


Thanks,
ltctech

Daniil
Jan 29, 2013, 4:44 AM
Hi @ltctech,

I think it is a good workaround. Thank you for sharing!

FpNetWorth
Jan 29, 2013, 7:18 AM
Hi,

I have the exact same issue, though I think I have found an easy workaround for the time being.
Just remove ForceSelection from ComboBox and stick it into AfterRender listener.
Seems to populate my value I set in Page_Load and ForceSelection still works.



<Listeners>
<AfterRender Handler="this.forceSelection = true;" />
</Listeners>


Thanks,
ltctech

Thank you @ltctech.
It's a good idea.
I'll try it.

ltctech
Jan 30, 2013, 3:47 AM
There is an additional side effect to setting ComboBox Value from Page_Load in 2.1.1.

If the Value set at Page_Load is not changed before postback, it will only postback the ComboBox's text (verified with FireBug).
In result, the server side Value will be populated with the text instead of the value.

If the Value is changed before postback by the user by selecting something else on client side, it will postback state with the json ListItem.
In this case the server side value is correct.

I switched my ComboBoxes to SimpleSubmit="true" and it appears to avoid this problem.
It essentially forces the Value to be sent in _ControlID_state param alone.
Has its own side effect in that SelectedItem.Text is now the same as SelectedItem.Value, even though _ControlID param had the text.

ltctech
Jan 30, 2013, 6:01 AM
Figured out a different way of setting value that works regardless of ForceSelection attribute.
More importantly, it does postback fine too with SelectedItem working as expected.

Add this extension method to a static utility class and it just works:


public static void SetValueAfterLoad(this Ext.Net.ComboBox combo, object value)
{
combo.Listeners.AfterRender.Handler = string.Format("this.store.on('load', function(){{ this.setValue({0}); }}, this)", value);
}


In essence, it registers with the ComboBox's store load event, and when the load event fires it goes ahead and sets the value in the ComboBox.
Something tells me there is a race condition with store load in ExtJS as calling setValue right after rendering causes an incomplete postback.

ltctech
Jan 30, 2013, 6:13 AM
Or this way, attaching directly to store without afterrender of combo:


public static void SetValueAfterLoad(this Ext.Net.ComboBox combo, object value)
{
combo.GetStore().Listeners.Load.Handler = string.Format("#{{{0}}}.setValue({1});", combo.ID, value);
}

FpNetWorth
Jan 30, 2013, 7:59 AM
There is an additional side effect to setting ComboBox Value from Page_Load in 2.1.1.

If the Value set at Page_Load is not changed before postback, it will only postback the ComboBox's text (verified with FireBug).
In result, the server side Value will be populated with the text instead of the value.


Hi itctech,

I had the same problem you talk about.
It was a bug and it's fixed.
Please refer to the following link:http://forums.ext.net/showthread.php?22763-CLOSED-ComboBox-load-value

ltctech
Apr 25, 2013, 10:36 PM
Any update on this bug from Sencha?
Kind of weird that it's still not been fixed now that Ext JS 4.2 is RTM.

Have you guys considered using this workaround internally in Ext.NET, when ForceSelection is set to true?


<Listeners>
<AfterRender Handler="this.forceSelection = true;" />
</Listeners>

Daniil
May 01, 2013, 10:06 AM
No news from Sencha, it is still opened.

Yes, we will consider fixing it direct in Ext.NET. Thanks.

Daniil
May 01, 2013, 12:47 PM
We are reluctant to commit such a fix

<AfterRender Handler="this.forceSelection = true;" />
and would prefer to wait a fix from Sencha.

Moreover, the issue doesn't look critical since you can use the SelectedItems property instead of the Value one.

this.ComboBox2.SelectedItems.Add(new Ext.Net.ListItem(2));

We would recommend to always use the SelectedItems property to set up initially selected items.

rbtceo
May 15, 2014, 5:01 AM
Hi All,

I am just wondering if is there any success with the issue?

Thank you.

Daniil
May 15, 2014, 6:13 AM
Sencha has not fixed it. We neither. Please use a workaround.