[CLOSED] DateField data format problem

  1. #1

    [CLOSED] DateField data format problem

    I have the following problem with the DateField control:

    context: I set the Culture by code as follows:

    ((ResourceManager) objControl). Locale = "en-US"
    I also force the date format to match the server's format with:

    dpClosingDate.Format = "d/m/Y";
    and I get the following unexpected result:
    I enter "23/9/2011" into the control and when it loses the focus, the value changes automatically to 9/11/2012.
    If I enter 23/09/2011 it doesn't happen.

    Another unexpected case is:
    I enter "09/23/2011" (it should fail the validation because the format is d/m/y). But when the control loses focus it's refreshed automatically to 09/11/2012. I'd expect a validation error message.

    This is the code of the page:

    <ext:Window ID="itemWindow" runat="server" Title="Periods" Icon="Time"
        Width="410px" Height="188px" AutoShow="false" Modal="true" Hidden="true" Resizable="false" BodyBorder="false">
        <Items>
            <ext:Panel ID="pnlGeneral" runat="server" Border="true" BodyStyle="padding:5px;">
                <Content>
                    <ext:FormPanel ID="frmGeneral" 
                        runat="server" 
                        MonitorPoll="500" 
                        MonitorValid="true" 
                        AutoWidth="true" 
                        Title="Periods Edition"
                        PaddingSummary="8px 8px 0"
                        BodyStyle="padding:5px;"
                        Layout="Form">
                    <Defaults>
                        <ext:Parameter Name="MsgTarget" Value="side" />
                    </Defaults>
                    <Items>
                        <ext:DateField 
                            ID="dpClosingDate" runat="server" Vtype="daterange" FieldLabel="Closing date" AllowBlank="false" >  
                            <CustomConfig>
                                <ext:ConfigItem Name="endDateField" Value="#{dpPaymentDate}" Mode="Value" />
                            </CustomConfig>                        
                        </ext:DateField>
                        <ext:DateField 
                            ID="dpPaymentDate" runat="server" Vtype="daterange" FieldLabel="Payment date" AllowBlank="false" >    
                            <CustomConfig>
                                <ext:ConfigItem Name="startDateField" Value="#{dpClosingDate}" Mode="Value" />
                            </CustomConfig>                                 
                        </ext:DateField>
                    </Items>
                </ext:FormPanel>
                </Content>
            </ext:Panel>
        </Items>
    </ext:Window>
    Last edited by Daniil; Oct 09, 2010 at 5:07 PM. Reason: [CLOSED]
  2. #2
    Hi asztern,

    I think you just need to use .NET DateTime format specifiers.

    Example

    pClosingDate.Format = "d/M/yyyy";
    Or, don't set the .Format and let the Component get this information automatically from the CurrentCulture.

    I think the DateField/DatePicker should use "d" as the default format, which will change depending on the Culture.
    Geoffrey McGill
    Founder
  3. #3
    Thanks Geoffrey

    Setting Up the Format property to "d/M/yyyy" solved my first problem but not the second.

    any other ideas to solve the second problem?
  4. #4
    Hi asztern,

    I would suggest you the following way to achieve your requirement.

    1. Clear AltFormats,
    2. Override the internal safeParse method to get supporting "strict" behavior during parsing (strange that it is not supported by default),
    3. Set Strict to true.

    Here is an implementation.

    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>
        <ext:ResourcePlaceHolder runat="server" />
    
        <script type="text/javascript">
            Ext.form.DateField.override({
                safeParse: function(value, format) {
                    if (/[gGhH]/.test(format.replace(/(\\.)/g, ''))) {
    
                        return Date.parseDate(value, format, this.strict);
                    } else {
    
                        var parsedDate = Date.parseDate(value + ' ' + this.initTime, format + ' ' + this.initTimeFormat, this.strict);
    
                        if (parsedDate) {
                            return parsedDate.clearTime();
                        }
                    }
                }
            });
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" Locale="en-US" />
        <ext:DateField runat="server" Format="d/M/yyyy" Strict="true" AltFormats=" " />
        </form>
    </body>
    </html>
    See also
    http://dev.sencha.com/deploy/dev/doc...ber=altFormats
    http://dev.sencha.com/deploy/dev/doc...mber=parseDate
  5. #5
    If you would like apply the "strict" behavior globally for an application the useStrict property of Date class would help.

    A solution can look like this.

    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" Locale="en-US">
            <Listeners>
                <DocumentReady Handler="Date.useStrict = true;"/>
            </Listeners>
        </ext:ResourceManager>
        <ext:DateField runat="server" Format="d/M/yyyy" AltFormats=" " />
        </form>
    </body>
    </html>
    See also
    http://dev.sencha.com/deploy/dev/doc...Date&useStrict
  6. #6
    Thanks Daniil

    I implemented your last suggestion, and it fixed the problem.

Similar Threads

  1. [CLOSED] DateField Format
    By rnfigueira in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 18, 2011, 12:39 PM
  2. [CLOSED] DateField and Format
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 07, 2009, 6:21 PM
  3. Replies: 3
    Last Post: Mar 17, 2009, 9:42 AM
  4. [CLOSED] DateField format
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 20, 2009, 9:47 AM
  5. [CLOSED] 0.4.6 : DateField format as dd/mm/yyy
    By stevejebson in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Oct 13, 2008, 3:14 PM

Posting Permissions