PDA

View Full Version : [CLOSED] Is there any way to know where the focus is going?



supera
Jan 25, 2012, 12:51 PM
Is there any way to know where the focus is going?

When the cancel button is clicked, I do not want trigger the event Blur...
I do not want trigger this event when switching between windows...



<DirectEvents>
<Blur OnEvent="GetDevedor">
<EventMask ShowMask="true" Target="CustomTarget" CustomTarget="={#{wndDividas}.body}" />
</Blur>
</DirectEvents>


Thanks for any help

Daniil
Jan 25, 2012, 1:08 PM
Hi,

I'm not sure what is the "cancel" button you are talking about? Please clarify. Do you use Confirmation?

Also please clarify the Blur event of what control?

Which windows are you switching and how?

supera
Jan 25, 2012, 3:43 PM
Hi Daniil...

I create a btnOk ('Ok' button) and a btnCancel ('Cancel' button) in a window... Ok button confirm the changed in records and cancel button close without save changes...

The unwanted behavior what I am having is the following:
1 - The 'blur' event of txtCPF, (CPF - Cadastro de Pessoa Física - Individual ID for any person of Brazil... like the SSN in USA), call a procedure when I try find a customer in my DB with the CPF number and if the customer is found, the field txtDevedor is filled... otherwise, the 'Customer Window' is started for add a new customer.

2 - When cancel button is clicked (I want close the window only, cancel adding of new record), the 'blur' event of txtCPF is fired..
which is an undesirable situation...

The code of my Window follow:



<ext:Window
ID="wndDividas"
runat="server"
Icon="MoneyAdd"
Title="Dívida"
Width="590"
Height="370"
AutoShow="false"
Modal="true"
Resizable="false"
PaddingSummary="5px 5px 5px 5px"
Hidden="true"
ButtonAlign="Right"
Layout="FitLayout">
<Items>
<ext:Panel ID="Panel1" runat="server" Border="true" BodyPadding="6" Header="false">
<Items>
<ext:FieldSet runat="server" ID="fsContrato" Title="Informações do Contrato" Layout="AbsoluteLayout" Height="190px" PaddingSummary="5px 5px 5px 5px">
<Defaults>
<ext:Parameter Name="LabelAlign" Value="Top" Mode="Value" />
</Defaults>
<Items>
<ext:ComboBox runat="server" ID="cmbTipoPessoa" FieldLabel="Tipo" X="5" Y="0" Width="120px">
<Items>
<ext:ListItem Text="Pessoa" Value="1" />
<ext:ListItem Text="Empresa" Value="0" />
</Items>
<SelectedItems>
<ext:ListItem Value="0" />
</SelectedItems>
<DirectEvents>
<Select OnEvent="SetCPForCNPJ"/>
</DirectEvents>
</ext:ComboBox>
<ext:TextField runat="server" ID="txtCPF" EnableKeyEvents="true" FieldLabel="CNPJ" x="135" Y="0" Width="140px" Validator="ValidaCPF_CNPJ" ValidateOnBlur="true">
<Listeners>
<KeyUp Fn="KeyUpHandler" />
</Listeners>
<DirectEvents>
<Blur OnEvent="GetDevedor">
<EventMask ShowMask="true" Target="CustomTarget" CustomTarget="={#{wndDividas}.body}" />
</Blur>
</DirectEvents>
</ext:TextField>
<ext:TextField runat="server" ID="txtDevedor" FieldLabel="Devedor" Disabled="true" DisabledClass="x-item-disable" x="285" Y="0" Width="225px" />
<ext:Toolbar ID="Toolbar1" runat="server" Cls="form-toolbar" Flat="true" X="512" Y="15">
<Items>
<ext:Button ID="btnDevedorEdit" runat="server" Text="" Icon="ApplicationEdit" >
<DirectEvents>
<Click OnEvent="Edit_Devedor" />
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
<ext:TextField runat="server" ID="txtContrato" FieldLabel="Contrato Nº" MaxLength="30" x="5" Y="45" Width="80px" />
<ext:DateField runat="server" ID="dtVencimentoOriginal" FieldLabel="Vencimento Original" LabelWidth="120" AltFormats="d/m/Y|j/n/Y|j/n/y|j/m/y|d/n/y|j/m/Y|d/m/Y|d-m-y|d-m-Y|d/m|d-m|dm|dmy|dmY|d|d-m-Y" Format="dd/MM/yyyy" X="95" Y="45" Width="120px"/>
<ext:TextField runat="server" ID="txtJuro" FieldLabel="Juro (%)" Text="0,00" MaxLength="10" FieldStyle="text-align:right" EnableKeyEvents="true" X="225" Y="45" Width="85px">
<Listeners>
<KeyUp Fn="KeyUpHandler_Money" />
</Listeners>
</ext:TextField>
<ext:TextField runat="server" ID="txtMulta" FieldLabel="Multa (%)" Text="0,00" MaxLength="10" FieldStyle="text-align:right" EnableKeyEvents="true" X="320" Y="45" Width="85px">
<Listeners>
<KeyUp Fn="KeyUpHandler_Money" />
</Listeners>
</ext:TextField>
<ext:DateField runat="server" ID="dtDataCobranca" FieldLabel="Data de Cobrança" AltFormats="d/m/Y|j/n/Y|j/n/y|j/m/y|d/n/y|j/m/Y|d/m/Y|d-m-y|d-m-Y|d/m|d-m|dm|dmy|dmY|d|d-m-Y" Format="dd/MM/yyyy" X="415" Y="45" Width="120px" />
<ext:TextArea runat="server" ID="txtObservacoes" FieldLabel="Observações" MaxLength="150" EmptyText="Insira aqui informações que agilizem a cobrança da dívida." X="5" Y="90" Height="40" Width="530" />
<ext:DisplayField runat="server" ID="dsMsg" X="5" Y="150" Width="500px" FieldStyle="font-size:9px" Text="*O número do contrato identifica a dívida junto ao cliente(loja). Pode ser o nº da nota fiscal, duplica, cheque, etc." />
</Items>
</ext:FieldSet>
<ext:FieldSet runat="server" ID="fsParcela" Title="Parcela" Layout="AbsoluteLayout" Height="95px" PaddingSummary="5px 5px 5px 5px">
<Defaults>
<ext:Parameter Name="LabelAlign" Value="Top" Mode="Value" />
</Defaults>
<Items>
<ext:TextField runat="server" ID="txtParcelaNumero" MaxLength="30" FieldLabel="Parcela" X="5" Y="0" Width="120px" />
<ext:TextField runat="server" ID="txtParcelaDescricao" MaxLength="100" FieldLabel="Descrição" X="135" Y="0" Width="250px" />
<ext:TextField runat="server" ID="txtValor" FieldLabel="Valor (R$)" MaxLength="15" Text="0" FieldStyle="text-align:right" EnableKeyEvents="true" X="395" Y="0" Width="140px">
<Listeners>
<KeyUp Fn="KeyUpHandler_Money" />
</Listeners>
</ext:TextField>
<ext:Checkbox runat="server" ID="chkSpc" HideLabel="true" X="5" Y="45" />
<ext:DisplayField runat="server" ID="dsChkSpc" X="25" Y="47" Text="Inscrito no Serviço de Proteção ao Crédito - SPC" />
</Items>
</ext:FieldSet>
</Items>
</ext:Panel>
</Items>
<Buttons>
<ext:Button runat="server" id="btnOk" text="Ok" Width="80px" Icon="Tick">
<DirectEvents>
<Click OnEvent="SaveDivida" Failure="Ext.MessageBox.alert('Saving failed', 'Error during ajax event');">
<EventMask ShowMask="true" Target="CustomTarget" CustomTarget="={#{wndDividas}.body}" />
</Click>
</DirectEvents>
</ext:Button>
<ext:Button runat="server" id="btnCancel" text="Cancelar" Width="80px" Icon="Cancel">
<DirectEvents>
<Click OnEvent="Cancel_Click" />
</DirectEvents>
</ext:Button>
</Buttons>
</ext:Window>

Daniil
Jan 25, 2012, 10:38 PM
I would avoid to use Blur to make a searching request to server. I would prefer to implement a button like "Search".

Though, if you persist with your scenario, please try the following solution.

Example

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

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

<script runat="server">
protected void TextField_Blur(object sender, DirectEventArgs e)
{
X.Msg.Alert("DirectEvent", "TextField_Blur").Show();
}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:TextField ID="TextField1" runat="server">
<Listeners>
<Focus Handler="delete this.preventBlur;" />
</Listeners>
<DirectEvents>
<Blur
OnEvent="TextField_Blur"
Before="if (this.preventBlur) {
delete this.preventBlur;
return false;
}"
Delay="250" />
</DirectEvents>
</ext:TextField>
<ext:Button runat="server" Text="Ok" />
<ext:Button runat="server" Text="Cancel">
<Listeners>
<Click Handler="#{TextField1}.preventBlur = true;" />
</Listeners>
</ext:Button>
</form>
</body>
</html>

supera
Jan 26, 2012, 2:35 PM
Thanks for the code that sent me ... works beautifully.

Thanks a lot!