PDA

View Full Version : [CLOSED] Combo BeforeSelect Event



softmachine2011
Sep 06, 2012, 9:21 AM
Hi,

When I have a beforeselect listener in a combo with a function inside it seems to loop the event fire. Or at least in v1.x with the same code doesn't have the same behaviour.

TEST CASE


<html>
<head runat="server">
<title>Ext.NET Examples</title>
<script type="text/javascript">
var myFunction = function (combo, record, index) {
var newValue = record.data.field1;

combo.collapse();

var messageWindow = Ext.Msg.show({ title: 'App Title',
msg: 'My question message....?',
buttons: Ext.Msg.YESNO,
fn: function (buttonId) {
if (buttonId == 'yes') {
combo.setValue(newValue);
}
},
icon: Ext.Msg.QUESTION
});

return false;
}
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:ComboBox runat="server">
<Items>
<ext:ListItem Text="Item 1" Value="1" Mode="Raw" />
<ext:ListItem Text="Item 2" Value="2" Mode="Raw" />
<ext:ListItem Text="Item 3" Value="3" Mode="Raw" />
</Items>
<Listeners>
<BeforeSelect Fn="myFunction" />
</Listeners>
</ext:ComboBox>
</form>
</body>
</html>

In my project I reproduce it with an store not with items inside the combo. If it might helps you.

Daniil
Sep 06, 2012, 10:49 AM
Hi,

The setValue method causes a Select event to be fired.

I can suggest to lock BeforeSelect listener before the setValue call and unlock after.

Example

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

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Examples</title>

<script type="text/javascript">
var onBeforeSelect = function (combo, record) {
if (!combo.lockedBeforeSelect) {
Ext.Msg.show({
title : 'Confirmation',
msg : 'Are you sure?',
buttons : Ext.Msg.YESNO,
icon : Ext.Msg.QUESTION,
fn : function (buttonId) {
if (buttonId === 'yes') {
combo.lockedBeforeSelect = true;
combo.setValue(record.get(combo.valueField));
combo.lockedBeforeSelect = false;
}
}
});

return false;
}
};
</script>
</head>
<body>
<ext:ResourceManager runat="server" />

<ext:ComboBox runat="server">
<Items>
<ext:ListItem Text="Item 1" Value="1" Mode="Raw" />
<ext:ListItem Text="Item 2" Value="2" Mode="Raw" />
<ext:ListItem Text="Item 3" Value="3" Mode="Raw" />
</Items>
<Listeners>
<BeforeSelect Fn="onBeforeSelect" />
</Listeners>
</ext:ComboBox>
</body>
</html>

softmachine2011
Sep 07, 2012, 9:12 AM
Ok I had applied this fix.

Thanks