Forum OpenACS Q&A: Re: ad_form and dates

Collapse
3: Re: ad_form and dates (response to 1)
Posted by Cathy Sarisky on
Thanks Jon. Actually, I already had the page open, which got me as far as I've gotten. When I use
to_sql(linear_date),from_sql(sql_date_no_time)
as in your example (for expiration date), the insert for new data doesn't work, with the error:
Bad date external representation '1995 02 05 00 00 00'
): '
            insert into ptk_reports
              (report_id, report_text, reported_date)
            values
              (nextval('ptk_report_seq'), 'new post, following Jon''s ad_form', '1995 02 05 00 00 00')'
(I'm also still not getting values for existing data editing.)
Collapse
4: Re: ad_form and dates (response to 3)
Posted by Tilmann Singer on
I don't know exactly how to do this in ad_form, but here's what works for me in a plain form builders if { [form is_request] } ... block:

db_1row ... { select to_char(start_date, 'YYYY-MM-DD') ... }

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

Maybe you can put that in an -on_request block of ad_form and modify it somehow so that it works?

Side note: I think the {reported_date ""} line should be removed - the form builder takes care of variables declared with it automatically. Otherwise you risk producing a "Move back and correct your error" message instead of the inline error message for that field.

Collapse
5: Re: ad_form and dates (response to 3)
Posted by Tilmann Singer on
Maybe simply removing the {value {$reported_date}} element from the field definition will do the trick - wouldn't that always set it to an empty value? Maybe it overrides whatever -select_query would have set.