Dear all, I created a form with 2 text_field_with_auto_complete fields and a submit button. I am able to get the auto complete feature to work. However, I am unable to read the values of the two text fields when I click the submit button. The classic way with @varname params[:field_value] does not seem to work. Thanks, Nick, --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-Mar-05 08:01 UTC
Re: Retrieve value of text_field_with_auto_complete field
Hey Nick, Nick a écrit :> I created a form with 2 text_field_with_auto_complete fields and a > submit button. I am able to get the auto complete feature to work. > However, I am unable to read the values of the two text fields when I > click the submit button. The classic way with @varname > params[:field_value] does not seem to work.m''kkayyy, basic questions first: - Are your fields indeed *in* the form you''re submitting, DOM-wise? - Did you make sure they were provided with a non-empty name= attribute? - At submission time, are they deemed successful (e.g. enabled, in this case)? If all this fails, two more paths: - Hook a handler to the form''s submit event and console.log or alert its serialize() method result. Check for your fields. - Post the details of your form opening and helper calls, in template order, in this thread... Maybe we''ll see something you forgot to mention. -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for your answer. I''m new to ruby and here is my code:
index.rhtml:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;
charset=utf-8"/>
<title>Mezzoo.com</title>
<%= javascript_include_tag :defaults %>
</head>
<body>
<h1>Input Places</h1>
<fieldset>
<% form_tag do %>
<p>
<label for="search2_origin_place">Origin
Place:</
label>
<%= text_field_with_auto_complete :city, :namestate %>
</p>
<p>
<label
for="search2_destination_place">Destination
Place:</label>
<%= text_field_with_auto_complete :city, :namestate %>
</p>
<p>
<%= submit_tag "Start Search" %>
</p>
<% end %>
</fieldset>
</body>
</html>
-------------------------------------
here is the controller code for search2_controller.rb:
class Search2Controller < ApplicationController
auto_complete_for :city, :namestate
def index
if request.post?
@origin_place = params[:origin_place]
@destination_place = params[:destination_place]
redirect_to({ :action => "map_places", :origin_place =>
@origin_place,
:destination_place =>
@destination_place, })
end
end
def map_places()
@origin_place = params[:origin_place]
@destination_place = params[:destination_place]
end
end
------------------------------
Here is the code for map_places.rhtml:
<h1>Map Places</h1>
<p>
Origin Place: <%= @origin_place %>
</p>
<p>
Destination Place: <%= @destination_place %>
</p>
---------------
I must be missing something easy.
Thanks,
On Mar 5, 3:01 am, Christophe Porteneuve
<t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org>
wrote:> Hey Nick,
>
> Nick a �crit :
>
> > I created a form with 2 text_field_with_auto_complete fields and a
> > submit button. I am able to get the auto complete feature to work.
> > However, I am unable to read the values of the two text fields when I
> > click the submit button. The classic way with @varname > >
params[:field_value] does not seem to work.
>
> m''kkayyy, basic questions first:
>
> - Are your fields indeed *in* the form you''re submitting,
DOM-wise?
> - Did you make sure they were provided with a non-empty name= attribute?
> - At submission time, are they deemed successful (e.g. enabled, in this
> case)?
>
> If all this fails, two more paths:
>
> - Hook a handler to the form''s submit event and console.log or
alert its
> serialize() method result. Check for your fields.
> - Post the details of your form opening and helper calls, in template
> order, in this thread... Maybe we''ll see something you forgot to
mention.
>
> --
> Christophe Porteneuve a.k.a. TDD
> "[They] did not know it was impossible, so they did it." --Mark
Twain
> Email: t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
I actually got a little better. I updated the search2_controller.rb
index method code with this:
def index
if request.post?
@origin_place = params[:city][:namestate]
@destination_place = params[:city][:namestate]
redirect_to({ :action => "map_places", :origin_place =>
@origin_place,
:destination_place =>
@destination_place, })
end
end
Now I am able to get the origin_place. However, destination_place is
the same as origin_place. The URL generated by the clicking the Submit
button is:
http://localhost:3001/search2/map_places?destination_place=Ambler%2C+PA&origin_place=Ambler%2C+PA
How come is it returning the same city name for both origin and
destination ?
Thanks,
Nick,
On Mar 5, 8:50 pm, "Nick"
<nhi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Thanks for your answer. I''m new to ruby and here is my code:
>
> index.rhtml:
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <meta http-equiv="content-type" content="text/html;
charset=utf-8"/
>
> <title>Mezzoo.com</title>
>
> <%= javascript_include_tag :defaults %>
>
> </head>
> <body>
>
> <h1>Input Places</h1>
> <fieldset>
> <% form_tag do %>
> <p>
> <label for="search2_origin_place">Origin
Place:</
> label>
> <%= text_field_with_auto_complete :city, :namestate
%>
> </p>
> <p>
> <label
for="search2_destination_place">Destination
> Place:</label>
> <%= text_field_with_auto_complete :city, :namestate
%>
> </p>
> <p>
> <%= submit_tag "Start Search" %>
> </p>
> <% end %>
> </fieldset>
> </body>
> </html>
>
> -------------------------------------
> here is the controller code for search2_controller.rb:
>
> class Search2Controller < ApplicationController
>
> auto_complete_for :city, :namestate
>
> def index
>
> if request.post?
> @origin_place = params[:origin_place]
> @destination_place = params[:destination_place]
> redirect_to({ :action => "map_places", :origin_place
=>
> @origin_place,
> :destination_place =>
> @destination_place, })
> end
>
> end
>
> def map_places()
>
> @origin_place = params[:origin_place]
> @destination_place = params[:destination_place]
>
> end
>
> end
>
> ------------------------------
>
> Here is the code for map_places.rhtml:
>
> <h1>Map Places</h1>
>
> <p>
> Origin Place: <%= @origin_place %>
> </p>
>
> <p>
> Destination Place: <%= @destination_place %>
> </p>
>
> ---------------
>
> I must be missing something easy.
>
> Thanks,
>
> On Mar 5, 3:01 am, Christophe Porteneuve
<t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:
>
> > Hey Nick,
>
> > Nick a ?crit :
>
> > > I created a form with 2 text_field_with_auto_complete fields and
a
> > > submit button. I am able to get the auto complete feature to
work.
> > > However, I am unable to read the values of the two text fields
when I
> > > click the submit button. The classic way with @varname > >
> params[:field_value] does not seem to work.
>
> > m''kkayyy, basic questions first:
>
> > - Are your fields indeed *in* the form you''re submitting,
DOM-wise?
> > - Did you make sure they were provided with a non-empty name=
attribute?
> > - At submission time, are they deemed successful (e.g. enabled, in
this
> > case)?
>
> > If all this fails, two more paths:
>
> > - Hook a handler to the form''s submit event and console.log
or alert its
> > serialize() method result. Check for your fields.
> > - Post the details of your form opening and helper calls, in template
> > order, in this thread... Maybe we''ll see something you
forgot to mention.
>
> > --
> > Christophe Porteneuve a.k.a. TDD
> > "[They] did not know it was impossible, so they did it."
--Mark Twain
> > Email: t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-Mar-06 08:22 UTC
Re: Retrieve value of text_field_with_auto_complete field
Hey Rick, Since you use the exact same code for both your AC''s, they share the same default name for their respective fields. I didn''t test, but this probably means you''ll get both serialized under the same name, with no trailing ''[]'' on the name, meaning you''ll only fetch one of the fields from the server side. You need to provide more parameters to your helper functions so that they equip your two fields with specific nameand id= attributes. BTW, since there are no differenciating parameters for their IDs, the for= attributes in your labels are useless... On a sidenote, <fieldset> is designed to be *inside* a <form>, and is rather useless without a child <legend> element. -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---