Henning Kilset Pedersen
2005-Sep-06 13:10 UTC
Silly AJAX question (read : newbie alert) - checkbox vs link_to_remote
Hello. I have a form that needs to be different depending on if the customer being created is a person or organization. I''m just prototyping the application right now, so most of the actual methods etc. aren''t implemented yet. What I wish to do is have two radio-buttons with Person/Organization - and an AJAX call to instantly show the right form based on the radio button you click. I can''t figure out how to do it. Right now I have two stupid, ugly link_to_remote links like so: ************* <% @heading = "New Customer" %> <%= javascript_include_tag "prototype" %> <%= error_messages_for ''customer'' %> <p><%= link_to_remote ("Customer is a person", :update => ''formdiv'', :url => { :action => :form_person } ) %> </p> <p><%= link_to_remote ("Customer is an organization", :update => ''formdiv'', :url => { :action => :form_organization } ) %> </p> <div id="formdiv"> </div> ************* the actions just do render (:layout => none) and hence load the corresponding .rhtml view file into the div. That works just fine. My question then - how can I run the ajax calls based on the (as of yet non-existant) radio buttons? And preferrably move the link_to_remote calls into a controller method to clean up the code somewhat?
pepe
2005-Sep-06 14:04 UTC
Re: Silly AJAX question (read : newbie alert) - checkbox vs link_to_remote
I think that best way to do this is to use observe_field or observer_form methods. Look to documentation on them. On 9/6/05, Henning Kilset Pedersen <henning@mopo.no> wrote:> Hello. > > I have a form that needs to be different depending on if the customer > being created is a person or organization. I'm just prototyping the > application right now, so most of the actual methods etc. aren't > implemented yet. > > What I wish to do is have two radio-buttons with Person/Organization - > and an AJAX call to instantly show the right form based on the radio > button you click. > > I can't figure out how to do it. Right now I have two stupid, ugly > link_to_remote links like so: > > ************* > > > <% @heading = "New Customer" %> > <%= javascript_include_tag "prototype" %> > <%= error_messages_for 'customer' %> > <p><%= link_to_remote ("Customer is a person", > :update => 'formdiv', > :url => { :action => :form_person } ) %> > </p> > <p><%= link_to_remote ("Customer is an organization", > :update => 'formdiv', > :url => { :action => :form_organization } ) %> > </p> > <div id="formdiv"> </div> > > > ************* > > the actions just do render (:layout => none) and hence load the > corresponding .rhtml view file into the div. That works just fine. > > My question then - how can I run the ajax calls based on the (as of yet > non-existant) radio buttons? And preferrably move the link_to_remote > calls into a controller method to clean up the code somewhat? > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails