This Question is Answered

15 "helpful" answers available (3 pts)
8 Replies Last post: Jul 11, 2008 5:29 AM by Kamal

about datefield

Jul 9, 2008 9:19 PM

Click to view taor's profile Level 2 taor 29 posts since
Jul 9, 2008

If I want to input date with fomart "mm/dd/ yyyy", what can i do?
Click to view fukuta's profile BlackBelt fukuta 118 posts since
Oct 17, 2007
1. Re: about datefield Jul 9, 2008 9:32 PM
We can use date-format-spec option to do that.

{DateField date-format-spec = "mdy"}
Click to view taor's profile Level 2 taor 29 posts since
Jul 9, 2008
2. Re: about datefield Jul 9, 2008 11:05 PM
in response to: fukuta

thank you very much! But,if the format is not fixed,how to do?

for example:

i want to input the date with "format1"(when focus into the datefield,the date is formated with format1) and i want to display the date with "format2" (when focus out the datefield,the date is formated with format2) .

format1 and format2 is not fixed.they are user defined.

now ,i can do the format change with method FocusIn and FocusOut, but when the format1 is not type of datetime ,i can't change the date.

source:

{self.add-event-handler
{on FocusIn do
set self.format-spec = {proc { date:DateTime,
df:DateField}:String
{return {Format self.value.info.locale-date, Format = self.Format}}
}
}
}

{self.add-event-handler
{on FocusOut do
set self.format-spec = {proc { date:DateTime,
df:DateField}:String
{return {Format self.value.info.locale-date, Format = self.DisplayFormat}}
}
}
}

Click to view fukuta's profile BlackBelt fukuta 118 posts since
Oct 17, 2007
3. Re: about datefield Jul 9, 2008 11:16 PM
in response to: taor
You might need to provide a parse-spec if you use your own format-spec.
This is note document from the api reference of a DateField.format-spec.

You will need to provide a DateField.parse-spec if you provide a DateField.format-spec that does not follow the following rules:
• The formatted value must have the day, month and year in the same order as DateField.date-format-spec.
• It does not use a member of DateField.separators to separate the day, month and year components of the date.
• It does not use an integer for the day or year.
• It does not use an integer between 1 and 12, or a member of CalendarControl.month-names or CalendarControl.short-month-names, for the associated CalendarControl, to represent the month.
Click to view Kamal's profile Curl Kamal 149 posts since
Oct 17, 2007
4. Re: about datefield Jul 10, 2008 6:24 AM
in response to: fukuta
That is right. The reason is that you can modify the DateField using the up and down arrow keys or the spin buttons. Depending on where the cursor is the date/month year can change. The DateField should have a way to know how to parse a random string.
Click to view taor's profile Level 2 taor 29 posts since
Jul 9, 2008
5. Re: about datefield Jul 10, 2008 6:42 PM
in response to: Kamal
That is right. when it has the drop down button,the value can be changed by selecting value.But when it has not the drop down button(Because of needing,the UI has been modified.Sometimes it maybe not have drop down button),the value can't be changed manually.
Click to view taor's profile Level 2 taor 29 posts since
Jul 9, 2008
6. Re: about datefield Jul 10, 2008 7:49 PM
in response to: taor

I think maybe the key is when focusout ,how to get the text what i input before format. what's your opinion?
Click to view Kamal's profile Curl Kamal 149 posts since
Oct 17, 2007
7. Re: about datefield Jul 11, 2008 5:23 AM
in response to: taor
I do not know about your custom UI. But if you are sub classing the StandardDateFieldUI then by just removing the Calendar drop down button will not make the DateField non editable.
Click to view Kamal's profile Curl Kamal 149 posts since
Oct 17, 2007
8. Re: about datefield Jul 11, 2008 5:29 AM
in response to: taor
I am not sure why you want to get the Text out of the DateField. In any case you can use "get-text" (see the example below). Also note that on FocusOut/ FocusIn I am also changing the date-format-spec which forces the DateFieldUI to show DateField.value in the new date format spec.

{curl 6.0 applet}
 
{let constant frm:Frame = {Frame}}
{value frm}
 
{let constant df:DateField =
    {DateField
        value = {DateTime.date},
        date-format-spec = "mdy",
        {on FocusIn at df:DateField do
            set df.date-format-spec = "dmy"
        },
        {on FocusOut at df:DateField do
            {frm.add {df.get-text}, replace? = true}
            set df.date-format-spec = "mdy"
        }   
    }
}
 
{value df}