PDA

View Full Version : [CLOSED] TimeField is not valid when loading grid record to a form



Geenin
Mar 15, 2014, 10:39 AM
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.

Daniil
Mar 17, 2014, 6:36 AM
Hi @Paggy,

Please provide a full runnable sample.

Geenin
Mar 17, 2014, 4:42 PM
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;

Daniil
Mar 17, 2014, 4:52 PM
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.

Geenin
Mar 18, 2014, 3:14 AM
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; }
}

Daniil
Mar 18, 2014, 5:24 AM
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>

Geenin
Mar 24, 2014, 4:53 AM
Hi Danii,

It works perfectly, thanks a lot!