Reputation: 23
I'm trying to use the calendar_date_select plug-in in my rails app and am 80% of the way there. I've got this in one of my views:
<%= calendar_date_select_tag "calendar", "",
:embedded => true,
:year_range => 10.years.ago..0.years.ago %>
The calendar shows up just fine, but I can't figure out how to get the value of the selected date into a usable variable. I've seen examples like
$F('calendar')
$F(this)
but haven't had any luck. Any help would be appreciated, thanks.
Upvotes: 1
Views: 1198
Reputation: 1805
The one I sue called CalendarHelper efines a helper called calendar that accepts a block. The block is called for each day and you yield an array with two values [text of the cell (ussually day number),class and css style options]
<%= calendar(:year=>year,:month=>month,:abbrev=>(0..1)) do |d|
cell_text = link_to_remote(d.mday,:update=>"panel",:url=>{:controller=>'portal',:action=>'agenda',:fecha=>d.to_time})+'<br />'
cell_attrs = nil
[cell_text, cell_attrs]
end
%>
I put a link_to_remote AJAX call in the text of the calendar so the number itself is the action caller.
But you can put a javascript assignment that sets any variable of any form to the value you want, like
...link stuff..."onClick='my_form.my_date.value=#{d.to_time};'"...
Upvotes: 0
Reputation: 20667
To access the <input>
object created by calendar_date_select
, you would use
$('calendar')
if you are using the Prototype javascript framework (default in Ruby on Rails) or
$('#calendar')
if you are using the JQuery javascript framework (if you have the JRails plugin/gem installed).
The libraries have slightly varied ways to access the value of that input so check out the documentation for the one you are using.
Cheers!
Upvotes: 1