Hi guys, I have been working on a form that would use javascript to validate the data before submitting it, and from my view.rhtml I have a statement like this: However such a statement generates a HTML tag that looks like this: <form action="/users/Login?onSubmit=validate%28%29" method="post"> Seems like Rails thinks it is a parameter instead of an option, so what I tried next was something like: <%= start_form_tag {:action => ''Add''}, {:onSubmit => ''validate()''} %> Sadly that doesn''t compile. From rubydocs the syntax for form_tag is form_tag(url_for_options = {}, options = {}, *parameters_for_url), so how do I specify the options that I''d want as in this case? Thanks! -- Posted via http://www.ruby-forum.com/.
Woei Shyang wrote:> <%= start_form_tag {:action => ''Add''}, {:onSubmit => ''validate()''} %> > > Sadly that doesn''t compile. From rubydocs the syntax for form_tag is > form_tag(url_for_options = {}, options = {}, *parameters_for_url), so > how do I specify the options that I''d want as in this case?Just had the same problem. You need to use parentheses around all of the arguments: <%= start_form_tag( {:action => ''Add''}, {:onSubmit => ''validate()''} ) %> -- Marshall Roch P.S. I realize this is old, but I found it so I figured I''d pass it on for others. -- Posted via http://www.ruby-forum.com/.
Marshall Roch wrote:> Woei Shyang wrote: >> <%= start_form_tag {:action => ''Add''}, {:onSubmit => ''validate()''} %> >> >> Sadly that doesn''t compile. From rubydocs the syntax for form_tag is >> form_tag(url_for_options = {}, options = {}, *parameters_for_url), so >> how do I specify the options that I''d want as in this case? > > Just had the same problem. You need to use parentheses around all of > the arguments: > > <%= start_form_tag( {:action => ''Add''}, {:onSubmit => ''validate()''} ) %> > > -- > Marshall Roch > > P.S. I realize this is old, but I found it so I figured I''d pass it on > for others.Correct. The problem is ruby has a hard time distinguishing between passed hashes, and associated blocks tacked onto method calls. Using parens fixes the issue since hashes would be isnside the parens, and blocks would be outside. -- Posted via http://www.ruby-forum.com/.
hi when i do this.... <%= start_form_tag( {:action => ''Add''}, {:onSubmit => :confirm=>''are you sure''} ) %> the popup appears but both the ok and cancel buttons, no matter which you you select, submits the form... how can i make it so that if the user selects cancel or ok, that the form does not get submit and enables the user to recheck the information? Alex Wayne wrote:> Marshall Roch wrote: >> Woei Shyang wrote: >>> <%= start_form_tag {:action => ''Add''}, {:onSubmit => ''validate()''} %> >>> >>> Sadly that doesn''t compile. From rubydocs the syntax for form_tag is >>> form_tag(url_for_options = {}, options = {}, *parameters_for_url), so >>> how do I specify the options that I''d want as in this case? >> >> Just had the same problem. You need to use parentheses around all of >> the arguments: >> >> <%= start_form_tag( {:action => ''Add''}, {:onSubmit => ''validate()''} ) %> >> >> -- >> Marshall Roch >> >> P.S. I realize this is old, but I found it so I figured I''d pass it on >> for others. > > Correct. The problem is ruby has a hard time distinguishing between > passed hashes, and associated blocks tacked onto method calls. Using > parens fixes the issue since hashes would be isnside the parens, and > blocks would be outside.-- 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 -~----------~----~----~----~------~----~------~--~---
had a hunt around, seems you might need a ''return'' for your validation. something like... <%= form_tag( {:action => ''Add''}, {:onSubmit => ''return validate();''} ) %> then in your validate(); javascript function you can put the validation code, returning true if ok, and false if not. -- 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 -~----------~----~----~----~------~----~------~--~---