Oct 23, 2014, 11:21 AM
[CLOSED] Problem with change event of comboboxes
I've noticed a strange bug with combobox and change event. To reproduce, please follow the steps below.
1 - Select some value in the first combobox (with keyboard, type "a", then "enter" to select the value).
2 - Press "tab" to leave the combobox.
3 - Change event gets correctly fired, since the value was changed (i used an alert in the example to check if the event would be fired).
4 - Close the alert window with "enter". The focus is set to the second combobox.
5 - Press "shift + tab" to return to the first combobox.
6 - Now wipe it's value with "backspace" and press "tab" two times: the first time, the value that was in the combobox before being wiped is selected, and the second time the control is left, the focus being set in the second combobox (loses it's focus). Since the value was not changed, change event is not fired, which is fine (the control was wiped, but since the least selected value was "forced" back, when control lost it's focus it still had the previous value).
7 - Press "shift + tab" again to come back to the first combobox.
8 - If you wipe the content of the combobox with backspace, unlike in the first time, the previous value is no longer "forced" back. It does get actually wiped.
Now comes the problem:
9 - When you press tab, the combobox loses it's focus, that is placed on the second combobox. But the change event is not fired. That's wrong, since the value actually changed: it had some value selected and now it's blank, so the change event should have been fired.
1 - Select some value in the first combobox (with keyboard, type "a", then "enter" to select the value).
2 - Press "tab" to leave the combobox.
3 - Change event gets correctly fired, since the value was changed (i used an alert in the example to check if the event would be fired).
4 - Close the alert window with "enter". The focus is set to the second combobox.
5 - Press "shift + tab" to return to the first combobox.
6 - Now wipe it's value with "backspace" and press "tab" two times: the first time, the value that was in the combobox before being wiped is selected, and the second time the control is left, the focus being set in the second combobox (loses it's focus). Since the value was not changed, change event is not fired, which is fine (the control was wiped, but since the least selected value was "forced" back, when control lost it's focus it still had the previous value).
7 - Press "shift + tab" again to come back to the first combobox.
8 - If you wipe the content of the combobox with backspace, unlike in the first time, the previous value is no longer "forced" back. It does get actually wiped.
Now comes the problem:
9 - When you press tab, the combobox loses it's focus, that is placed on the second combobox. But the change event is not fired. That's wrong, since the value actually changed: it had some value selected and now it's blank, so the change event should have been fired.
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
s.DataSource = s2.DataSource = s3.DataSource = new List<Object>()
{
new { Codigo = "A123" , Descricao = "A - 123"},
new { Codigo = "A456" , Descricao = "A - 456"},
new { Codigo = "A789" , Descricao = "A - 789"},
new { Codigo = "B123" , Descricao = "B - 123"},
new { Codigo = "B456" , Descricao = "B - 456"},
new { Codigo = "B789" , Descricao = "B - 789"}
};
s.DataBind();
s2.DataBind();
s3.DataBind();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<ext:ResourceManager runat="server" ID="rm1"></ext:ResourceManager>
<ext:ComboBox runat="server" ID="c"
Mode="Local"
Width="500" ValueField="Codigo" DisplayField="Descricao">
<Listeners>
<Change Handler="alert('changed!');" />
</Listeners>
<Store>
<ext:Store runat="server" ID="s">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="Codigo"></ext:RecordField>
<ext:RecordField Name="Descricao"></ext:RecordField>
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
</ext:ComboBox>
<ext:ComboBox runat="server" ID="c2"
Mode="Local"
Width="500" ValueField="Codigo" DisplayField="Descricao">
<Listeners>
<Change Handler="alert('changed!');" />
</Listeners>
<Store>
<ext:Store runat="server" ID="s2">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="Codigo"></ext:RecordField>
<ext:RecordField Name="Descricao"></ext:RecordField>
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
</ext:ComboBox>
<ext:ComboBox runat="server" ID="c3"
Mode="Local"
Width="500" ValueField="Codigo" DisplayField="Descricao">
<Listeners>
<Change Handler="alert('changed!');" />
</Listeners>
<Store>
<ext:Store runat="server" ID="s3">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="Codigo"></ext:RecordField>
<ext:RecordField Name="Descricao"></ext:RecordField>
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
</ext:ComboBox>
</div>
</form>
</body>
</html>
Last edited by Daniil; Nov 06, 2014 at 1:29 PM.
Reason: [CLOSED]