[CLOSED] TimeField is not valid when loading grid record to a form

  1. #1

    [CLOSED] TimeField is not valid when loading grid record to a form

    Hi Ext.Net,

    I have a FormPanel and a GridPanel. When user double click on a row, the system will load record to the form. The question is that I have a TimeField and always gets the message like "07:00:00 is not a valid" (because the correct format should be HH:mm).

    Could you please let me know how to solve it? Thanks!

    The ModelField:
    <ext:ModelField Name="SCHEDULE_ON" DateReadFormat="HH:mm" />
    To load a record to the form:
    <ItemDblClick Handler=" #{_extFormPanel}.getForm().loadRecord(record); "></ItemDblClick>
    The TimeField:
    <ext:TimeField ID="Time_ScheduleTime" FieldLabel="Schedule Time" LabelAlign="Right" 
                           Name="SCHEDULE_ON" Editable="false" runat="server" MinTime="00:00" MaxTime="23:00" Increment="60" Format="HH:mm" />
    The DB column type is [time], MS SQL.
    Last edited by Daniil; Mar 24, 2014 at 4:08 AM. Reason: [CLOSED]
  2. #2
    Hi @Paggy,

    Please provide a full runnable sample.
  3. #3
    Hi Danii,

    Thanks! Here is .aspx code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test2.aspx.cs" Inherits="sample.Dashboard.Test2" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:FormPanel ID="FormPanel1" runat="server" Layout="AnchorLayout" AutoDataBind="true">
            <Items>
                <ext:Panel runat="server" ID="Panel1" Padding="8" Layout="HBoxLayout" Border="false">
                    <Items>
                        <ext:TimeField Name="SEND_ON" FieldLabel="Schedule Time" Width="120" LabelAlign="Right" HideLabel="true"
                            ID="Time_ScheduleTime" Editable="false"
                            runat="server"
                            MinTime="00:00"
                            MaxTime="23:00"
                            Increment="60"
                            SelectedTime="07:00"
                            Format="HH:mm" />
                    </Items>
                </ext:Panel>
                <ext:GridPanel Layout="FitLayout" ID="GridPanel1" runat="server" Title="Test List" Height="230"
                    EnableColumnHide="false">
                    <Store>
                        <ext:Store ID="Store1" runat="server" AutoLoad="true">
                            <Model>
                                <ext:Model ID="Model1" runat="server" IDProperty="_ID">
                                    <Fields>
                                        <ext:ModelField Name="REPORT_NAME" />
                                        <ext:ModelField Name="SEND_ON" DateReadFormat="HH:mm" />
                                    </Fields>
                                </ext:Model>
                            </Model>
                        </ext:Store>
                    </Store>
                    <ColumnModel ID="ColumnModel1" runat="server">
                        <Columns>
                            <ext:Column ID="Column4" runat="server" Flex="1" Text="NAME" AutoDataBind="true" Width="140" DataIndex="REPORT_NAME"></ext:Column>
                            <ext:Column ID="Column1" runat="server" Flex="1" Text="SEND_ON" AutoDataBind="true" Width="140" DataIndex="SEND_ON"></ext:Column>
                        </Columns>
                    </ColumnModel>
                    <Listeners>
                        <SelectionChange Handler="
                                        if (selected[0]) 
                                        { 
                                            this.up('form').getForm().loadRecord(selected[0]); 
                                        }" />
                    </Listeners>
                    <SelectionModel>
                        <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" Mode="Single" />
                    </SelectionModel>
                </ext:GridPanel>
            </Items>
        </ext:FormPanel>
    </body>
    </html>
    I do DataBind() in Page_Load and the data comes from MS SQL with column type as [time], so the "SEND_ON" member of entity is like
    private System.TimeSpan _SEND_ON;
  4. #4
    Quote Originally Posted by Geenin View Post
    I do DataBind() in Page_Load and the data comes from MS SQL with column type as [time], so the "SEND_ON" member of entity is like
    private System.TimeSpan _SEND_ON;
    Please provide that part as well, but without the dependance from a database. Please use some dummy test data.
  5. #5
    Quote Originally Posted by Daniil View Post
    Please provide that part as well, but without the dependance from a database. Please use some dummy test data.
    Hi Danii,

    The below is my testing code:
            protected void Page_Load(object sender, EventArgs e)
            {
                List<TEST> _ts = new List<TEST>();
                _ts.Add(new TEST());
    
                this.GridPanel1.GetStore().DataSource = _ts;
                this.GridPanel1.GetStore().DataBind();
            }
    
            public class TEST
            {
                public string REPORT_NAME { get; set; }
                public System.TimeSpan SEND_ON { get; set; }
            }
  6. #6
    Thanks.

    A DateField's DateReadFormat is used only if its Type is Date.

    You could try with a Convert function.
    <ext:ModelField Name="SEND_ON">
        <Convert Handler="return value.substr(0,5);" />
    </ext:ModelField>
  7. #7
    Hi Danii,

    It works perfectly, thanks a lot!

Similar Threads

  1. [CLOSED] [1.7] Validating form if one of two fields is valid
    By lapix in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Oct 15, 2013, 11:21 AM
  2. [CLOSED] fire the DirectEvent ONLY when form is valid
    By Fahd in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 07, 2012, 1:00 PM
  3. [CLOSED] Disable Selection on TreePanel on form no valid
    By rbarr in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Dec 14, 2011, 9:35 AM
  4. Insert Record Form Panel
    By lindgrenm in forum 1.x Help
    Replies: 17
    Last Post: May 17, 2011, 7:01 PM
  5. [CLOSED] Form status bar without valid icon
    By 78fede78 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 05, 2010, 4:40 PM

Posting Permissions