Mark Reginald J. wrote:
Kad, I just tried this out myself, and the class attribute was set
properly.
Can you post the relevant sections of your controller and view as they
now stand? And how are you determining that the class has not changed?
it’s quite tricky… I am using the unobtrusive Date-Picker Widgit ( see
demo frequency-decoder.com) from Brian
McAllister (he went on vacation yesterday…), as you can see in the
demo, the css class is used to drive the js (I am not js aware but
Brian seems to be very good in it…)
I need to capture a StartBookingDate and an EndBookingdate, the
EndBookingdate cannot be selected before the StartBookingDate, that’s
why I need to link both.
No problem on initial display (new) I cannot select an EndBookingdate
before the StartBookingDate.
When the StartBookingDate change (observe-field in the form) the
controller changes the EndBookingdate value (OK, text-field is modified)
and should modify the class : range-low-xx … of the datepicker
calendar…
Looking into the FX DOM, I can see that the class is changed, but it’s
not reflected in the source code of the page and EndBookingdate
selection in calendar did not change…
— Booking controller
def new
t = Time.now
@startdate = t.strftime(“%d/%m/%Y”)
@enddate = (t+(84600)).strftime(“%d/%m/%Y”)
@startdateclass = “format-d-m-y”
@enddateclass = “format-d-m-y range-low-” +
(t+(84600)).strftime(“%d-%m-%Y”)
end
— Booking new.rhtml
<%= start_form_tag :action => ‘create’ %>
<%= render :partial => ‘form’ %>
<%= submit_tag “Create” %>
<%= end_form_tag %>
— Booking _form.rhtml
text_field_tag('startdate', @startdate, {:class => @startdateclass,
:readonly => "readonly", :maxlength => "25"} ) %>
<%= observe_field("startdate", :frequency => 0.5, :url => {:controller
=> 'booking' , :action => 'startdateChanged' }, :update => 'enddate',
:with => "'input='+$('startdate').value ") %>
<%= text_field_tag('enddate', @enddate, {:class => @enddateclass,
:readonly => "readonly", :maxlength => "25"} ) %>
— Booking controller
def startdateChanged
pd = ParseDate::parsedate(@params[“input”])
tl = Time.local(pd[0], pd[1], pd[2])
# endate must be = startdate + 10 days
@enddate = (tl+(8460010)).strftime(“%d/%m/%Y”)
# range-low of calendar picker must be= startdate + 10 days
@enddateclass = “format-d-m-y range-low-” +
(tl+(8460010)).strftime(“%d-%m-%Y”)
render :update do | page |
page[‘enddate’].value = @enddate
page[‘enddate’].className = @enddateclass
end
end