Help with observe_field please!

Hi there I’m observing a field (collection_select) but if the
collection only has one item, the observe field will not work, it
works for more than one item
here is my code
<%= collection_select ‘address’, ‘address’, @addresses, :id, :address
%>


<%= observe_field(
:address_address,
:update => ‘shipping’,
:url => { :action => :shi },
:on => “onselect”,
:complete => “new Effect.SlideDown(‘shipping’)”,
:with => ‘boo’) %>

I have tried a different of bunch :on => event
but no efect
any help would be very aprreciated

Hi Jorge,

Jorge Mario G. Mazo wrote:

Hi there I’m observing a field (collection_select) but if the
collection only has one item, the observe field will not work

That’s because, with only one item in the collection, there’s no event
occurring. I think you’ll have to force the event by using a blank
item,
maybe with ‘select one’ for the text at the beginning of the collection.
Check the option_from_collection_for_select documentation. You may need
to
modify your approach a little. It says ‘you have to wrap this call in a
regular HTML select tag.’

Another option would be to render your UI differently depending on the
number of items in the collection.

hth,
Bill

On Mar 13, 2007, at 12:31 AM, Jorge Mario G. Mazo wrote:

          :url => { :action => :shi },
          :on => "onselect",
          :complete => "new Effect.SlideDown('shipping')",
          :with => 'boo')  %>

I have tried a different of bunch :on => event
but no efect
any help would be very aprreciated

To save you a dive down into the prototype.js library (since I was
just there a week ago ;-), the only event that the underlying
JavaScript supports is an implicit ‘change’ or ‘click’ depending on
the element type (click for radio buttons and checkboxes, change for
others).

I spent several hours tracking down odd behavior which was partly
explained by this. (The other part was having an autocomplete and
and observe-field on the same form element – nasty timing issues
there!)

-Rob

Rob B. http://agileconsultingllc.com
[email protected]