Forum OpenACS Development: ad_form and dates

Collapse
Posted by Jon Griffin on
It appears that ad_form (and even the templating system) don't play nice with dates.

I have just spent 4 hours trying to get the date widget to honor value and it just plain doesn't work. Of course I could be totally screwing something up, but in porting my code (which had the Michael Cleverly hacks) it all stops working.

I am going through the mess of date procs and it seems that the widget stuff wants a list. Has anyone else used the 4.6 templating system with dates as default values?

Collapse
2: Re: ad_form and dates (response to 1)
Posted by Don Baccus on
I have, yes, and haven't forgotten your e-mail note.  I've been too busy to dig through your example to see why it isn't working.
Collapse
3: Re: ad_form and dates (response to 1)
Posted by Don Baccus on
Ummm ... what might not work is arbitrary format strings for dates which was only partially implemented by aD.  When I fixed things so the minimal functionality worked I did not tackle that as implementing it involves writing a format-string driven date parser.

But I don't think offhand that the format you're using should cause a problem.

sqldate is the acquire-side thing you need to translate a date string to the date type's list format.  lineardate on the output side dumps the list as a string of space-delimited elements.

Collapse
4: Re: ad_form and dates (response to 1)
Posted by Tilmann Singer on
Lacking the example code that seems to be buried in private email I can only state that in general it works for me, like this:
if { [form is_request edit] } {
    db_1row get_times {
        select
        to_char(start_date, 'YYYY-MM-DD') as start_date,
        ...
    }

    element set_value edit start_date [util::date acquire clock [clock scan $start_date]]
}

Collapse
5: Re: ad_form and dates (response to 1)
Posted by Lars Pind on
The value that you need to pass to the element has to be in this format:

YYYY MM DD HH24 MI

I think this is regardless of the format you're using for the widget.

Try that and see if that helps.

/Lars

Collapse
6: Re: ad_form and dates (response to 1)
Posted by Jon Griffin on
Lars,
That didn't change anything. The value doesn't even show up.
Collapse
7: Re: ad_form and dates (response to 1)
Posted by Jon Griffin on
After more experimentation (frustration).

Not using ad_form works with -value [util::date acquire clock [clock scan $start_date]]

If I use this in ad_form with {value {[util::date acquire clock [clock scan $start_date]]}} it doesn't work.

Lars suggestion also results in no default.

It appears that ad_form is the problem.

Collapse
8: Re: ad_form and dates (response to 1)
Posted by Ola Hansson on
Jon, This works in ad_form for me:
set all_widgets {}
lappend all_widgets \
	[list start_date:date {value {[util::date acquire clock [clock scan 2003-01-15]]}} optional]
ad_form -name spell \
    -mode edit \
    -cancel_url / \
    -cancel_label "Get outta here" \
    -confirm_template confirm \
    -spellcheck_template spellcheck \
    -spellcheck_label "Spell Away" \
    -form $all_widgets \
    -on_submit {

    # What now?

}
Collapse
9: Re: ad_form and dates (response to 1)
Posted by Jon Griffin on
What version of ad_form are you using? It must be from the head because those switches aren't in 4.6.

Anyway it doesn't work for me.

Collapse
10: Re: ad_form and dates (response to 1)
Posted by Jon Griffin on
OK, I did get it working. It seems that the linear_date is the problem. I will run some more tests and see if submits work properly (I think they do).
Collapse
11: Re: ad_form and dates (response to 1)
Posted by Don Baccus on
Linear date is, I think, wrong on the acquire side.  The acquire side expects a string, corresponding to the "sql_date" ad_form translation name.

For all data types, "acquire" means "convert from Tcl string to internal format".  Linear date is the *internal* format which is a list.  Not quite the same as a Tcl string ...

Collapse
12: Re: ad_form and dates (response to 1)
Posted by Jon Griffin on
I thought I tried sql_date, but I will try it again tommorrow.

Using the tcl clock technique seems to work fine also, so I am not sure that the whole sql_date/linear_date conversion thing is even necessary.

Collapse
13: Re: ad_form and dates (response to 1)
Posted by Jon Griffin on
Don, sql_date works. Now which should be the official supported version. I will update my docs when this is decided.

Re: docs, I am going to attempt to document the whole ATS/Form api next week so if anyone has some comments or examples please send them off.

Collapse
14: Re: ad_form and dates (response to 1)
Posted by Jon Griffin on
I am going through the templating and forms et al for new docs and have found several big errors in the parser.

For example: format "MONTH DD YYYY HH" shows up as:

March 9 2003 2003
Month Day Year Year
I will test all these and probably rewrite them using more extended masks.

Also, 2 date fields in a row causes many problems. So, off I go to rewrite the parser. Maybe I should just write it in yacc and be done with it ;)