Hi all, I am trying to clear a form once the info is being submitted to the database. Basically what I have is a form that makes use of the form_remote_tag which adds a list of credit cards to a list and then adds that info to a database. What I want to happen is that once the submit button is hit the form clears so that the user can enter another credit card if they so choose. what I have tried is adding an :onclick to my submit_tag helper: <%= submit_tag "Add Credit Card Information, :onclick => ''clear_credit_card_form()'' %> which called a JavaScript method that bascially went like: document.getElementById( "exp_date" ).value = " "; to just clear the form, which it did. However, it cleared the form before the POST so nothing got through to the database and an exception was thrown. Anyone have any hints and how I could handle this. Thanks, ~S -- 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 -~----------~----~----~----~------~----~------~--~---
Shandy Nantz wrote:> Hi all, > > I am trying to clear a form once the info is being submitted to the > database. Basically what I have is a form that makes use of the > form_remote_tag which adds a list of credit cards to a list and then > adds that info to a database. What I want to happen is that once the > submit button is hit the form clears so that the user can enter another > credit card if they so choose. what I have tried is adding an :onclick > to my submit_tag helper: > > <%= submit_tag "Add Credit Card Information, :onclick => > ''clear_credit_card_form()'' %> > > which called a JavaScript method that bascially went like: > > document.getElementById( "exp_date" ).value = " "; > > to just clear the form, which it did. However, it cleared the form > before the POST so nothing got through to the database and an exception > was thrown. Anyone have any hints and how I could handle this. Thanks, > > ~SHello Are you using rjs? If so, i think you can use page[''form_id''].reset in your create.rjs -- 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 -~----------~----~----~----~------~----~------~--~---
I''m a noobie at this, so this might seem like a dumb question, but how do you add an id to the form tag? What I have is: <%= form_remote_tag :update => "credit_card_table", :url => { :action => :add_credit_card, :id => @user } %> if I do something like: <%= form_remote_tag :update => "credit_card_table", :id => "credit_card_form", :url => { :action => :add_credit_card, :id => @user } %> the raw html doesn''t show an id attirbute and thus my .rjs file does nothing. Another thing is what do I call the .rjs file? If the file that has the form is edit_form.rhtml should I name my rjs file edit_form.rjs? I''m just a little confused on how the code in the .rjs file get excuted. Thanks, ~S -- 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 -~----------~----~----~----~------~----~------~--~---
Shandy Nantz wrote:> I''m a noobie at this, so this might seem like a dumb question, but how > do you add an id to the form tag? What I have is: > > <%= form_remote_tag :update => "credit_card_table", :url => { :action => > :add_credit_card, :id => @user } %> > > if I do something like: > > <%= form_remote_tag :update => "credit_card_table", :id => > "credit_card_form", :url => { :action => :add_credit_card, :id => @user > } %> > > the raw html doesn''t show an id attirbute and thus my .rjs file does > nothing. Another thing is what do I call the .rjs file? If the file that > has the form is edit_form.rhtml should I name my rjs file edit_form.rjs? > I''m just a little confused on how the code in the .rjs file get excuted. > Thanks, > > ~S1. Try <%= form_remote_tag :update => "credit_card_table", :url => { :action => :add_credit_card, :id => @user}, :html => { :id = ''form_id'' }%> By the way check out form_remote_for, i think this helper fits better your needs.(http://api.rubyonrails.org/) 2. You should name your rjs file after the method you are trying to execute in your controller. So create method will have create.rjs. -- 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 -~----------~----~----~----~------~----~------~--~---
Im not sure what''s going on. I have a web apps book for Ruby on Rails which describes the same things that you have been suggesting as far as the .rjs file goes but it is not working. I have matched the method name with the .rjs file and have given all the html elements the proper id''s, but it''s still not working. I don''t think it is excuting the .rjs file, but I don''t see why. I''ll keep messing with. Thanks for your help. It''s all about learning new things and I have learned a lot even if it''s not cooperating. ~S -- 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 -~----------~----~----~----~------~----~------~--~---
SHAZAM - I figured it out - well not really, I just figured out a new way to do it. So here it is; in my form_remote_tag I added: :complete=>''document.getElementById("exp_date").value = ""; The problem taht I had before was that I was using this exact same JavaScript to clear the form, but it cleared it before it posted the info, making is usless, plus it crashed on top of that. I imagine what :complete does is post first then execute the JavaScript. But that''s how I got it to work, now I''m going on break! ~Shandy -- 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 -~----------~----~----~----~------~----~------~--~---