PDA

View Full Version : How to set default input type for the Date Field



sandeep9763
18 Jan 2011, 1:27 AM
While i am using the DateField eg:01062001 it will display as 06-jun-2001 ,but i want it to be displayed as 01-jan-2001..It is taking 3rd and 4th as date 1st and 2nd as month ,i need in reverse.

danguba
18 Jan 2011, 2:11 AM
Read API
http://dev.sencha.com/deploy/dev/docs/?class=Ext.form.DateField&member=format

sandeep9763
18 Jan 2011, 2:33 AM
thnx danguba ,
In order to do that ,do i need to write the whole dateFiled ? by replacing my own format..

joeri
18 Jan 2011, 2:35 AM
Also look at
http://dev.sencha.com/deploy/dev/docs/?class=Ext.form.DateField&member=altFormats

"format" specifies the default format for displaying and input, while altFormats specifies the alternate syntaxes. What you want is to change altFormats so it accepts fields in reversed order. In our app we have a global setting for US / ISO calendar format, and based on this format and altFormats are initialized to appropriate values on Ext.form.DateField.prototype

joeri
18 Jan 2011, 4:56 AM
Here is a simplified version of the script that does our calendar format:
- startDay: start day for calender picker (starts on sunday for us, starts on monday for iso)
- format: date format for display (differs)
- emptyText: empty hint text for date fields
- altFormats: input formats (the different formats that can be typed in a date field)


<?php
...
$bUseIsoCalendar = TRUE / FALSE;
$strCalendarStartDay = ($bUseIsoCalendar ? "1" : "0");
// n = month with optional leading zeroes; j = day of month with optional leading zeroes
$strDateFormat = ($bUseIsoCalendar ? "d/m/Y" : "m/d/Y");
$strDateFormatAlt = ($bUseIsoCalendar ? "j/n/Y|j-n-y|j-n-Y|j/n|j-n|dm|dmy|dmY|d|Y-n-j" : "n/j/Y|n-j-y|n-j-Y|n/j|n-j|md|mdy|mdY|d|Y-n-j");
$strDateEmpty = ($bUseIsoCalendar ? "dd/mm/yyyy" : "mm/dd/yyyy");
?>

if(Ext.util.Format){
Ext.util.Format.date = function(v, format){
if(!v) return "";
if(!(v instanceof Date)) v = new Date(Date.parse(v));
return v.dateFormat(format || <?php echo json_encode($strDateFormat); ?>);
};
}

if(Ext.DatePicker){
Ext.apply(Ext.DatePicker.prototype, {
format : <?php echo json_encode($strDateFormat); ?>,
startDay : <?php echo strval($strCalendarStartDay); ?>
});
}

if(Ext.form.DateField){
Ext.apply(Ext.form.DateField.prototype, {
emptyText : <?php echo json_encode($strDateEmpty);?>,
format : <?php echo json_encode($strDateFormat); ?>,
altFormats : <?php echo json_encode($strDateFormatAlt); ?>,
startDay : <?php echo strval($strCalendarStartDay); ?>
});
}