Access parsed date via Javascript?

15 views
Skip to first unread message

Jens

unread,
May 25, 2010, 1:50:12 AM5/25/10
to calendar_date_select
Hello,

is it currently possible to access the parsed date of a
calendar_date_select form field via JS?

I would like to do some client-side date calculations to show/hide
further options depending on the combination of dates a user enters
into a form.

I have tried $('my_date_input_field').calendar_date_select but this is
always undefined, regardless of what I have entered into the field.

Thank you!

--
You received this message because you are subscribed to the Google Groups "calendar_date_select" group.
To post to this group, send email to calendar_d...@googlegroups.com.
To unsubscribe from this group, send email to calendar_date_se...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/calendar_date_select?hl=en.

Shih-gian Lee

unread,
May 25, 2010, 7:41:55 AM5/25/10
to calendar_date_select
Hi Jens,

I don't think there is an easy way to access the parsed date in the
Calendar Date Select. The parsed date will be displayed in the input
field anyway. Can you do $('my_input_field').value to get the value
you want?

- Lee

Jens

unread,
May 30, 2010, 9:36:55 AM5/30/10
to calendar_date_select
Hi,

Then I would have to re-implement the date parser, which would break
when changing locales or date formatting. I needed to get a JS Date
object out of the input field. I figured it out:

function calendar_parse_date(element_id) {
// console.log("calendar_parse_date");
var cal = new CalendarDateSelect(element_id, { popup:false } );
cal.parseDate();
var cal_date = cal.selected_date;
cal.close();
return cal_date;
}

This might be total overkill but it works. The problem is only that it
takes the default date when no date has yet been selected.

Shih-gian Lee

unread,
May 30, 2010, 10:31:00 AM5/30/10
to calendar_date_select
Hi Jens,

Calendar Date Select can be used as standalone or used with Rails. If
you plan to use it as standalone, this documentation maybe helpful to
you - http://code.google.com/p/calendardateselect/wiki/JavascriptDocumentation.

Calendar Date Select comes with several callbacks. I believe you can
setup the call back and output the date or time anywhere you want it
in your html. You can check out the demo here - http://electronicholas.com/calendar.
As a note, the demo is a but outdated and may not have the latest
feature. So, please refer to the documentation.

I hope that helps.

- Lee

Jens

unread,
May 31, 2010, 1:35:49 AM5/31/10
to calendar_date_select
Thank you!

Actually, I need both: I need the JS date object to do client-side
form manipulation based on the date - and this starts when possibly no
date has yet been selected - AND I need the Rails helpers.

The callbacks in this case do not help since the CalendarDateSelect
instance is only created when a user clicks on the calendar - I need
the date even before that, for example on an edit form where the date
field is pre-populated but has not yet been modified.

Jens

On May 30, 4:31 pm, Shih-gian Lee <shih....@gmail.com> wrote:
> Hi Jens,
>
> Calendar Date Select can be used as standalone or used with Rails. If
> you plan to use it as standalone, this documentation maybe helpful to
> you -http://code.google.com/p/calendardateselect/wiki/JavascriptDocumentation.
>
> Calendar Date Select comes with several callbacks. I believe you can
> setup the call back and output the date or time anywhere you want it
> in your html. You can check out the demo here -http://electronicholas.com/calendar.
Reply all
Reply to author
Forward
0 new messages