AJAX Observe Form - problem with event handlers with :on

I have the following:

<%= observe_form “picker_form”,:frequency => 1,
:update => “frame_picker” ,
:loading_text => “Retrieving price…”,
:complete => visual_effect(:highlight,
“picker_live_price”, { :startcolor => “’#9b3801’”, :endcolor =>
“’#f0c18e’”, :duration => 0.5 }),
:url => { :controller => ‘store’,
:action => “update_picker” } %>

It works as expected, the result is that a form is redrawn to
dynamically populate drop-down lists. There is one problem - the AJAX
update triggers if the user just hovers over a new value in a drop-down.
The drop-down then disappears as the form is redrawn.

I want the AJAX to fire only when the user clicks on an option, not for
a hover. I’ve tried adding :on => “blur” to the observe_form call but it
doesn’t seem to make a difference.

I appreciate any help. I’m redrawing the entire form on the AJAX call -
my next step is to change to redrawing individual select dropdowns, but
that is a lot more code and it would appear from the api documentation
that if I can find the right event for the :on => ? that I can get it
working the way I want.

thanks.
c.

Remove :frequency statement.
In that case that will be event driven.

Aw crud on a stick - can it really be that simple? Could it really have
been right in front of me as I stared at the api docs?

:frequency: The frequency (in seconds) at which changes to this field
will be detected. Not setting this option at all or to a value equal to
or less than zero will use event based observation instead of time based
observation.

Yes. Yes.

Thanks so much Sergey. :slight_smile:

c.

Sergey K. wrote:

Remove :frequency statement.
In that case that will be event driven.

I also see that the RJS templates seem to trump the method I’m using in
a major way. I just grabbed the O’Reilly RJS Templates for Rails booklet
and it looks to be a gold mine.

c.

Sergey K. wrote:

Cayce B. wrote:

Aw crud on a stick - can it really be that simple? Could it really have
been right in front of me as I stared at the api docs?

:frequency: The frequency (in seconds) at which changes to this field
will be detected. Not setting this option at all or to a value equal to
or less than zero will use event based observation instead of time based
observation.

I was hit the same brick time ago =) As an old geek I always like to see
the actual code that’s how I realized
about it. Even if that was on front of me in documentation =)

Please note that it won’t work with radio buttons. Stop! Probably it may
if you will provide id name only on the last
element! In that case you can safely update any
DOM elements
via observe_(field|form ) with :complete field and I don’t have to use
remote_function which is doesn’t work properly
with IE on radiobuttons. Cool!
I have to check it.

Yes. Yes.

Thanks so much Sergey. :slight_smile:

You are very welcome!

All the Best!
Sergey.

Cayce B. wrote:

I also see that the RJS templates seem to trump the method I’m using in
a major way. I just grabbed the O’Reilly RJS Templates for Rails booklet
and it looks to be a gold mine.

c.

It looks like I will get my copy of that book soon =)))

or less than zero will use event based observation instead of time based
element! In that case you can safely update any

All the Best!
Sergey.

Cayce B. wrote:

Aw crud on a stick - can it really be that simple? Could it really have
been right in front of me as I stared at the api docs?

:frequency: The frequency (in seconds) at which changes to this field
will be detected. Not setting this option at all or to a value equal to
or less than zero will use event based observation instead of time based
observation.

I was hit the same brick time ago =) As an old geek I always like to see
the actual code that’s how I realized
about it. Even if that was on front of me in documentation =)

Please note that it won’t work with radio buttons. Stop! Probably it may
if you will provide id name only on the last
element! In that case you can safely update any
DOM elements
via observe_(field|form ) with :complete field and I don’t have to use
remote_function which is doesn’t work properly
with IE on radiobuttons. Cool!
I have to check it.

Yes. Yes.

Thanks so much Sergey. :slight_smile:

You are very welcome!

All the Best!
Sergey.

Hello, I have a similar proble with the :on property
I have the following code in the view

<%= start_form_tag :id => ‘AjaxForm’ %>
<%= text_field_tag :text1 %>
<%= text_field_tag :text2 %>
<%= observe_field :text1,
:url => {:action => ‘test’},
:update => ‘ajaxWrapper’,
:with => ‘text1’,
:on => ‘blur’ %>
<%= end_form_tag %>

The method ‘test’ is
def test
render :text => ‘hello world’
end

The thing is that the observer doesn’t trigger on blur and it does
trigger onchange (which is the default) even if I set it to :on =>
‘blur’.
The same happens with ‘click’, ‘focus’, and any other event that I try.

If someone knows something about it , please let me know.

Thanks

On Jun 21, 2007, at 11:20 PM, Fernando P. wrote:

                  :on => 'blur' %>

trigger onchange (which is the default) even if I set it to :on =>
‘blur’.
The same happens with ‘click’, ‘focus’, and any other event that I
try.

If someone knows something about it , please let me know.

Thanks

If you dive down into the source code, you find that the only :on
value that has support at the JavaScript level is ‘change’ and that
it is very specific. A few months ago I had to track down some
unexpected behavior (or more accurately the lack of expected
behavior) and discovered this. That was with Rails 1.1.6, but I
think it’s true at least as recently as 1.2.2

-Rob

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs