Wes Gamble
2007-Jan-17 18:06 UTC
AJAX select: How to send the selected value to AJAX action?
All,
I want to have a select box which sends it''s selected value to my
action
onChange.
Here''s what I have so far (there is no form):
<%= select(:preferences, :job_history_filter_period,
ContactPreference::JOB_HISTORY_OPTIONS, {},
:onChange => remote_function(:url => {:action =>
:modify_history_time_period})) %>
What is the correct way to get the selected value of the list box into
the request?
I assume that I have to modify the :parameters option of the Ajax
request, but not sure how to do that with the helper.
Thanks,
Wes
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Athanasios Kouroussis
2007-Jan-17 18:17 UTC
Re: AJAX select: How to send the selected value to AJAX action?
You can do this:
<%= select(:preferences, :job_history_filter_period,
ContactPreference::JOB_HISTORY_OPTIONS, {},
html_options = {
:onChange => "new Ajax.Request(
''/controller_name/modify_history_time_period/'' +
this[this.selectedIndex].value,
{asynchronous:true, evalScripts:true});"
}
) %>
It''s not as clean as the helper but gets the job done.
Cheers,
Atha
Wes Gamble wrote:>
> All,
>
> I want to have a select box which sends it''s selected value to my
action
> onChange.
>
> Here''s what I have so far (there is no form):
>
> <%= select(:preferences, :job_history_filter_period,
> ContactPreference::JOB_HISTORY_OPTIONS, {},
> :onChange => remote_function(:url => {:action =>
> :modify_history_time_period})) %>
>
> What is the correct way to get the selected value of the list box into
> the request?
>
> I assume that I have to modify the :parameters option of the Ajax
> request, but not sure how to do that with the helper.
>
> Thanks,
> Wes
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Wes Gamble
2007-Jan-17 18:19 UTC
Re: AJAX select: How to send the selected value to AJAX acti
How quickly we forget:
The solution:
<%= select(:preferences, :job_history_filter_period,
ContactPreference::JOB_HISTORY_OPTIONS, {},
:onChange => remote_function(:url => {:action =>
:modify_history_time_period},
:with => "''time_period='' +
this.options[this.selectedIndex].value")) %>
I need to help with the documentation effort - there is no mention of
the :with parameter anywhere in the API docs. for remote_function, nor
link_to_remote. If you look in the source for the options_for_ajax()
function, you''ll find the use of the :with parameter. But that seems a
little more difficult than it should be.
Thanks,
Wes
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Atha
2007-Jan-17 18:20 UTC
Re: AJAX select: How to send the selected value to AJAX action?
You can do this:
<%= select(:preferences,
:job_history_filter_period,
ContactPreference::JOB_HISTORY_OPTIONS,
options = {},
html_options = {
:onChange => "new
Ajax.Request(''/controller_name/modify_history_time_period/'' +
this[this.selectedIndex].value, {asynchronous:true,
evalScripts:true});"
}
) %>
It''s not as clean as the helper but gets the job done.
Cheers,
Atha
On Jan 17, 3:06 pm, Wes Gamble
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> All,
>
> I want to have a select box which sends it''s selected value to my
action
> onChange.
>
> Here''s what I have so far (there is no form):
>
> <%= select(:preferences, :job_history_filter_period,
> ContactPreference::JOB_HISTORY_OPTIONS, {},
> :onChange => remote_function(:url => {:action =>
> :modify_history_time_period})) %>
>
> What is the correct way to get the selected value of the list box into
> the request?
>
> I assume that I have to modify the :parameters option of the Ajax
> request, but not sure how to do that with the helper.
>
> Thanks,
> Wes
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Jason Roelofs
2007-Jan-17 19:30 UTC
Re: AJAX select: How to send the selected value to AJAX acti
You could also use a two-pronged approach:
<%= ... select box code :preferences, :job_history_filter_period %>
...
<%= observe_field ''preferences[job_history_filter_period], :update
=> ''some
field'', :url => {:action => :modify_history_time_period} %>
Though I do notice that you shouldn''t need the :with in the first
place. The
Rails helpers should automatically send back
params[:job_history_filter_period] through remote_function, though I may be
wrong.
Jason
On 1/17/07, Wes Gamble
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> How quickly we forget:
>
> The solution:
>
> <%= select(:preferences, :job_history_filter_period,
> ContactPreference::JOB_HISTORY_OPTIONS, {},
> :onChange => remote_function(:url => {:action =>
> :modify_history_time_period},
> :with => "''time_period='' +
> this.options[this.selectedIndex].value")) %>
>
> I need to help with the documentation effort - there is no mention of
> the :with parameter anywhere in the API docs. for remote_function, nor
> link_to_remote. If you look in the source for the options_for_ajax()
> function, you''ll find the use of the :with parameter. But that
seems a
> little more difficult than it should be.
>
> Thanks,
> Wes
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Wes Gamble
2007-Jan-17 21:21 UTC
Re: AJAX select: How to send the selected value to AJAX acti
Jason Roelofs wrote:> You could also use a two-pronged approach: > > <%= ... select box code :preferences, :job_history_filter_period %> > > ... > > <%= observe_field ''preferences[job_history_filter_period], :update => > ''some > field'', :url => {:action => :modify_history_time_period} %> > > Though I do notice that you shouldn''t need the :with in the first place. > The > Rails helpers should automatically send back > params[:job_history_filter_period] through remote_function, though I may > be > wrong. > > JasonJason, You''re right that I probably could have used an observer, but I don''t need to update anything on the page. I just need to notify the server that something has changed. The "automatically sending back params[:job_history_filter_period]" would happen if I were sending form contents back, but I''m not. Originally, I tried that (with a form_remote_tag around the select), but it wouldn''t work because you can''t use JS to submit a form. So I ended up with this approach, which is the most direct, I think. Thanks, Wes -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---