How to cancel DateField change event

  1. #1

    How to cancel DateField change event

    Hi,

    does there exist any solution how to cancel Date field change event.
    For example if I have
        <ext:DateField ID="WorkingDate" runat="server" Format="D" Width="180" ReadOnly="true"
                                            StartDay="1">
                                            <AjaxEvents>
                                            <Change  OnEvent="WorkingDate_Change" />
                                            </AjaxEvents>
                                        </ext:DateField>
    and want to make some validation in WorkingDate_Change and if something goes wrong cancel this change?

    Thanks,
    Z.
  2. #2

    RE: How to cancel DateField change event

    Hi zikr,

    An AjaxEvent has Before property. It is before request handler. You can perform check and return false if need cancel request


    Before="if(!TextField1.isValid()){return false;}"


    Before handler with params: el, type, action, extraParams



  3. #3

    RE: How to cancel DateField change event

    Hi, Vladimir.

    As understood this Before handler is client side java script code. But how can I call server side validation? And cancel
    changes if it fails? Or may be I need to use some another approach?

    P.S> your library is very exciting but there is no much documentation available...:( I'm currently developing prototype
    application and if it will satisfy requirements, we plan to buy commercial license.

    Thanks,
    Z.
  4. #4

    RE: How to cancel DateField change event

    Hi zikr,

    You can't cancel event. But you can set oldValue back if validation fail
    Please see example
    <%@ Page Language="C#" EnableViewState="false" %>
    <%@ Import Namespace="System.Globalization"%>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <!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 id="Head1" runat="server">
        <title>Example</title>
        <script runat="server">
            protected void WorkingDate_Change(object sender, AjaxEventArgs e)
            {
                CultureInfo provider = CultureInfo.InvariantCulture;
                DateTime oldValue = DateTime.MinValue;
                DateTime newValue = DateTime.MinValue;
    
                if (!string.IsNullOrEmpty(e.ExtraParams["oldValue"]))
                {
                    oldValue = DateTime.ParseExact(e.ExtraParams["oldValue"], "dd/MM/yyyy", provider);    
                }
                if (!string.IsNullOrEmpty(e.ExtraParams["newValue"]))
                {
                    newValue = DateTime.ParseExact(e.ExtraParams["newValue"], "dd/MM/yyyy", provider);
                }
    
                //some validation and if fail then revert value
                
                if(oldValue != DateTime.MinValue)
                {
                    DateField df = sender as DateField;
                    df.SetValue(oldValue);
                    df.AddScript("alert('{0}');", "The value change has been canceled");    
                }
            }
        </script>
    </head>
    <body style="padding:10px;">
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug" />
            
            <ext:DateField ID="WorkingDate" runat="server" Format="D" Width="180" ReadOnly="true"
                StartDay="1">
                <AjaxEvents>
                    <Change  OnEvent="WorkingDate_Change">
                        <ExtraParams>
                            <ext:Parameter Name="newValue" Value="newValue.format ? newValue.format('d/m/Y') : ''" Mode="Raw" />
                            <ext:Parameter Name="oldValue" Value="oldValue.format ? oldValue.format('d/m/Y') : ''" Mode="Raw" />
                        </ExtraParams>
                    </Change>
                </AjaxEvents>
            </ext:DateField>
        </form>
    </body>
    </html>

  5. #5

    RE: How to cancel DateField change event

    Vladimir, thanks. It was exactly what I required.
    You are very helpful.

    Z.


Similar Threads

  1. [CLOSED] Cancel Selection Change in Combobox
    By tlfdesarrollo in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: May 18, 2012, 2:14 PM
  2. [CLOSED] TreePanel: cancel node selection change event
    By coleg123 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Nov 03, 2011, 6:47 AM
  3. [CLOSED] Cancel button event if wrong date in datefield
    By nhg_itd in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Oct 11, 2011, 8:25 AM
  4. Replies: 2
    Last Post: Jun 16, 2011, 1:41 AM
  5. Cancel event based on its 'before' ajaxevent
    By jchau in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 01, 2008, 3:41 PM

Posting Permissions