Hi there,
Tis I yet again :)
I've no idea if this is a bug or not but I've run into the following problem.
Page / User Control contains one (or more) DateField controls.
In setting the "format" property I get mixed results after the page has posted back to the server.
My "format" property was original set to "yyyy/MM/dd", after reading about the specific formats allowed
(from the ext API docs) I ended up using "Y/n/j".
The only problem was that if I set / selected / specified a date and then caused a postback, the DateField
was not reset to the selected / specified value.
I thought that this was strange and then created a test page with 6 DateField controls, each control set to a different format.
Control 1 - 'Y/m/d'
Control 2 - 'Y/n/d'
Control 3 - 'Y/n/j'
Control 4 - 'yyyy/M/d'
Control 5 - 'yyyy/m/d'
Control 6 - 'yyyy/m/j'
Page contains 2 buttons:
1.) To set the date of all controls to the current date
2.) Button to trigger a postback
The following result occurs after setting the default dates and causing the postback:
Control 1 - Date not populated after postback
Control 2 - Date not populated after postback
Control 3 - Date not populated after postback
Control 4 - Date populated correctly
Control 5 - Date populated, but with the incorrect month. Year and Day are correct.
Control 6 - Date not populated after postback
It may be that I'm misunderstanding the allowable / usable Date formats, but I thought you should know my findings :)
Here follows the code for my test page:
<%@ Page Language="C#" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Test Page</title>
<ext:ScriptManager ID="extScriptManager" runat="server" CleanResourceUrl="true" />
</head>
<body>
<form id="form1" runat="server">
<div style="width:100%">
<table>
<tr>
<td width="35px" align="right">
<asp:Label ID="Label1" runat="server" Text="Test1:" Font-Names="Tahoma" Font-Size="8pt" />
</td>
<td width="5px" />
<td>
<ext:DateField
runat="server"
ID="DateField1"
Format="Y/m/d"
InvalidText="{0} is not a valid date - it must be in the format {1}"
AllowBlank="True">
</ext:DateField>
</td>
<td width="5px" />
<td>
<asp:Label ID="Label6" runat="server" Text="(Y/m/d)" Font-Names="Tahoma" Font-Size="8pt" />
</td>
</tr>
<tr>
<td width="35px" align="right">
<asp:Label ID="Label2" runat="server" Text="Test2:" Font-Names="Tahoma" Font-Size="8pt" />
</td>
<td width="5px" />
<td>
<ext:DateField
runat="server"
ID="DateField2"
Format="Y/n/d"
InvalidText="{0} is not a valid date - it must be in the format {1}"
EnableViewState="True">
</ext:DateField>
</td>
<td width="5px" />
<td>
<asp:Label ID="Label7" runat="server" Text="(Y/n/d)" Font-Names="Tahoma" Font-Size="8pt" />
</td>
</tr>
<tr>
<td width="35px" align="right">
<asp:Label ID="Label3" runat="server" Text="Test3:" Font-Names="Tahoma" Font-Size="8pt" />
</td>
<td width="5px" />
<td>
<ext:DateField
runat="server"
ID="DateField3"
Format="Y/n/j"
InvalidText="{0} is not a valid date - it must be in the format {1}"
EnableViewState="True">
</ext:DateField>
</td>
<td width="5px" />
<td>
<asp:Label ID="Label8" runat="server" Text="(Y/n/j)" Font-Names="Tahoma" Font-Size="8pt" />
</td>
</tr>
<tr>
<td width="35px" align="right">
<asp:Label ID="Label4" runat="server" Text="Test4:" Font-Names="Tahoma" Font-Size="8pt" />
</td>
<td width="5px" />
<td>
<ext:DateField
runat="server"
ID="DateField4"
Format="yyyy/M/d"
InvalidText="{0} is not a valid date - it must be in the format {1}"
EnableViewState="True">
</ext:DateField>
</td>
<td width="5px" />
<td>
<asp:Label ID="Label9" runat="server" Text="(yyyy/M/d)" Font-Names="Tahoma" Font-Size="8pt" />
</td>
</tr>
<tr>
<td width="35px" align="right">
<asp:Label ID="Label5" runat="server" Text="Test5:" Font-Names="Tahoma" Font-Size="8pt" />
</td>
<td width="5px" />
<td>
<ext:DateField
runat="server"
ID="DateField5"
Format="yyyy/m/d"
InvalidText="{0} is not a valid date - it must be in the format {1}"
EnableViewState="True">
</ext:DateField>
</td>
<td width="5px" />
<td>
<asp:Label ID="Label10" runat="server" Text="(yyyy/m/d)" Font-Names="Tahoma" Font-Size="8pt" />
</td>
</tr>
<tr>
<td width="35px" align="right">
<asp:Label ID="Label11" runat="server" Text="Test6:" Font-Names="Tahoma" Font-Size="8pt" />
</td>
<td width="5px" />
<td>
<ext:DateField
runat="server"
ID="DateField6"
Format="yyyy/m/j"
InvalidText="{0} is not a valid date - it must be in the format {1}"
EnableViewState="True">
</ext:DateField>
</td>
<td width="5px" />
<td>
<asp:Label ID="Label12" runat="server" Text="(yyyy/m/j)" Font-Names="Tahoma" Font-Size="8pt" />
</td>
</tr>
</table>
<br />
<asp:Button ID="Button1" runat="server" Font-Names="Tahoma" Font-Size="8pt" onclick="Button1_Click" Text="Click Me!"/>
<asp:Button ID="Button2" runat="server" Font-Names="Tahoma" Font-Size="8pt" Text="Set Default Dates" OnClientClick="setDates();return false;"/>
</form>
<script type="text/javascript">
function setDates() {
var date1 = Ext.getCmp("<%= DateField1.ClientID %>");
var date2 = Ext.getCmp("<%= DateField2.ClientID %>");
var date3 = Ext.getCmp("<%= DateField3.ClientID %>");
var date4 = Ext.getCmp("<%= DateField4.ClientID %>");
var date5 = Ext.getCmp("<%= DateField5.ClientID %>");
var date6 = Ext.getCmp("<%= DateField6.ClientID %>");
var today = new Date();
date1.setValue(today);
date2.setValue(today);
date3.setValue(today);
date4.setValue(today);
date5.setValue(today);
date6.setValue(today);
}
</script>
</body>
</html>
Regards Steven