[CLOSED] DateField: How to I simulate the date validation?

  1. #1

    [CLOSED] DateField: How to I simulate the date validation?

    Hi, I have a DateField with the following code:

    <ext:DateField ID="dfDateRangeFrom" runat="server" EndDateField="dfDateRangeTo" Vtype="daterange" Format="dd-MMM-yyyy" Width="120" AltFormats="d-MMM-yyyy">
      <ToolTips>
        <ext:ToolTip ID="ToolTip1" runat="server" Html="Press <b>ENTER</b> to activate filter" />
      </ToolTips>
      <Listeners>
        <Select Handler="ReloadTestList('dfDateRangeFrom');" />
        <SpecialKey Fn="enterKeyPressHandler" />
      </Listeners>
    </ext:DateField>
    If I enter a value like "1-NOV-2011", and click on another element, the value will automatically change to "01-NOV-2011". But if I do not click another field, the value will remain "1-NOV-2011" which will be considered as invalid (dfDateRangeFrom will contain 01/01/01 0001). My objective is to enable dfDateRangeFrom to recognize "1-NOV-2011" as a valid date so if there are an alternative solution, I will also appreciate it. Thanks!


    var enterKeyPressHandler = function(f, e) {
      if (e.getKey() == e.ENTER) {
    
       .......
      // this will send the 2 dates to the backend for processing
    
      }
    }
    Last edited by Daniil; Nov 22, 2011 at 7:27 AM. Reason: [CLOSED]
  2. #2
    Hi,

    The following DateField allows me to enter a date in two formats and consider it as valid.

    So, the issue is not clear for me, please clarify.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" 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 runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:DateField runat="server" Format="dd-MM-yyyy" AltFormats="d-MM-yyyy" />
        </form>
    </body>
    </html>
  3. #3
    Hi Daniil,

    If you enter a date "1-NOV-2011" then press enter, and then the javascript calls a DirectMethod, the value in the backend becomes "01/01/0001".

    var enterKeyPressHandler = function(f, e) {
      if (e.getKey() == e.ENTER) {
     
       .......
      // this will send the 2 dates to the backend for processing
      // Call a DirectMethod and process the date.
     
      }
    }
  4. #4
    I still can't reproduce the problem. Please provide your full test case.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        [DirectMethod]
        public void Test()
        {
            this.Label1.Text = "DirectMethod : " + DateTime.Now.ToString();
        }
    </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 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:DateField 
                runat="server" 
                Format="dd-MM-yyyy" 
                AltFormats="d-MM-yyyy">
                <Listeners>
                    <SpecialKey Handler="if (e.getKey() === e.ENTER) {
                                             Ext.net.DirectMethods.Test();
                                         }" />
                </Listeners>
            </ext:DateField>
            <ext:Label ID="Label1" runat="server" />
            <%--To avoid POSTBACK on Enter--%>
            <ext:TextField runat="server" Hidden="true" />
        </form>
    </body>
    </html>
  5. #5
    Hi Daniil, thanks for your quick support.

    My case scenario is like below:

    (1) When I type "1-MAY-2011" in DateField1 and then press ENTER, the Label2 will be "01/01/0001 12:00:00 AM".
    (2) When I type "1-MAY-2011" in DateField1 and then click DateField2, the value of DateField1 will automatically become "01-MAY-2011". Which when pressed ENTER will make Label2 = "01/05/2011 12:00:00 AM".

    I would like to know if there is any method I can run in the SpecialKey listener to simulate the auto-change to "dd-MMM-yyyy" format?

    <<%@ Page Language="C#" %>
      
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        [DirectMethod]
        public void Test()
        {
            this.Label1.Text = "DirectMethod : " + DateTime.Now.ToString();
            this.Label2.Text = "DirectMethod : " + this.DateField1.Value.ToString();
        }
    </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 id="Head1" runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:DateField ID="DateField1"
                runat="server"
                Format="dd-MMM-yyyy"
                AltFormats="d-MMM-yyyy">
                <Listeners>
                    <SpecialKey Handler="if (e.getKey() === e.ENTER) {
                                             Ext.net.DirectMethods.Test();
                                         }" />
                </Listeners>
            </ext:DateField>
            <ext:DateField ID="DateField2"
                runat="server"
                Format="dd-MM-yyyy"
                AltFormats="d-MM-yyyy">
            </ext:DateField>
            <ext:Label ID="Label1" runat="server" /><br />
            <ext:Label ID="Label2" runat="server" />
            <%--To avoid POSTBACK on Enter--%>
            <ext:TextField ID="TextField1" runat="server" Hidden="true" />
        </form>
    </body>
    </html>
  6. #6
    Now the requirement is clear.

    Please call the triggerBlur method.

    Example
    <SpecialKey Handler="if (e.getKey() === e.ENTER) {
                             this.triggerBlur();
                             Ext.net.DirectMethods.Test();
                         }" />
  7. #7
    Hi Daniil,

    It works perfectly. Thank you! Please close this ticket.

    best regards!

Similar Threads

  1. [CLOSED] Datefield validation
    By Pablo_Azevedo in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Sep 03, 2010, 1:01 PM
  2. [CLOSED] Validation of DateField
    By macap in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: May 11, 2010, 11:29 AM
  3. Replies: 3
    Last Post: May 06, 2010, 12:48 PM
  4. Validation for DateField
    By n_s_adhikari@rediffmail.com in forum 1.x Help
    Replies: 2
    Last Post: Sep 09, 2009, 5:00 PM
  5. Replies: 1
    Last Post: Jun 11, 2009, 2:09 PM

Posting Permissions