Hi Friends, I am a newbie on ROR, I made a authentication page for login. Now For Validation at client side I want Javascript to be used. Does Rails support client side vaildation as for server side methods are already available? Regards HUNT -- Posted via http://www.ruby-forum.com/.
Rails obviously support client side validation. all you need is to put onsubmit event on whatever the form syntax you are using. below is an example: <% form_tag ({:action => "new"}, {:onsubmit => "return validate();"}) %> then your basic javascript goes like: function validate(){ if(document.getElementById(''some_id'')=="") alert("specify first name"); } On Wed, Sep 9, 2009 at 11:46 AM, HUNT HUNT <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi Friends, > > I am a newbie on ROR, I made a authentication page for login. Now For > Validation at client side I want Javascript to be used. > > > Does Rails support client side vaildation as for server side methods are > already available? > > Regards > HUNT > -- > Posted via http://www.ruby-forum.com/. > > > >-- Thanks and Regards ___________________ Puneet Pandey Ruby on Rails Developer http://www.puneetitengineer.wordpress.com In Puneet''s Lab: http://www.puneetpandey.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 -~----------~----~----~----~------~----~------~--~---
Puneet Pandey wrote:> Rails obviously support client side validation. all you need is to put > onsubmit event on whatever the form syntax you are using. below is an > example: > > <% form_tag ({:action => "new"}, {:onsubmit => "return validate();"}) %> > > then your basic javascript goes like:--------------------------------------------------------------------------> function validate(){ > if(document.getElementById(''some_id'')=="") > alert("specify first name"); > } >Thanks Puneet, WHere this validate function is embedded in index.html.erb? Any reference for the same is a great hint. -------------------------------------------------------------------------> On Wed, Sep 9, 2009 at 11:46 AM, HUNT HUNT > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org >> wrote: > >> Regards >> HUNT >> -- >> Posted via http://www.ruby-forum.com/. >> >> > >> > > > -- > Thanks and Regards > > ___________________ > > Puneet Pandey > Ruby on Rails Developer > http://www.puneetitengineer.wordpress.com > In Puneet''s Lab: http://www.puneetpandey.com-- Posted via http://www.ruby-forum.com/.
You can put it anywhere.. in the index.html.erb or in layouts or in some external javascript.. in third case make sure that you are calling that javascript like <script src="/javascripts/yourjavascriptname.js"> On Wed, Sep 9, 2009 at 12:14 PM, HUNT HUNT <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Puneet Pandey wrote: > > Rails obviously support client side validation. all you need is to put > > onsubmit event on whatever the form syntax you are using. below is an > > example: > > > > <% form_tag ({:action => "new"}, {:onsubmit => "return validate();"}) %> > > > > then your basic javascript goes like: > -------------------------------------------------------------------------- > > function validate(){ > > if(document.getElementById(''some_id'')=="") > > alert("specify first name"); > > } > > > > > Thanks Puneet, > > WHere this validate function is embedded in index.html.erb? > Any reference for the same is a great hint. > ------------------------------------------------------------------------- > > On Wed, Sep 9, 2009 at 11:46 AM, HUNT HUNT > > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org > >> wrote: > > > >> Regards > >> HUNT > >> -- > >> Posted via http://www.ruby-forum.com/. > >> > >> > > >> > > > > > > -- > > Thanks and Regards > > > > ___________________ > > > > Puneet Pandey > > Ruby on Rails Developer > > http://www.puneetitengineer.wordpress.com > > In Puneet''s Lab: http://www.puneetpandey.com > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Thanks and Regards ___________________ Puneet Pandey Ruby on Rails Developer http://www.puneetitengineer.wordpress.com In Puneet''s Lab: http://www.puneetpandey.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 put the code but the result coming is that no action is performed on click the button. I haven''t found relevant information in google. -- Posted via http://www.ruby-forum.com/.
Ideally, javascript should be kept in head section of html, and for this you can use content_for tag. Read more about here: http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#M001763 Thanks, Abhinav -- अभिनव http://twitter.com/abhinav On Wed, Sep 9, 2009 at 2:31 PM, HUNT HUNT <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > I put the code but the result coming is that no action is performed on > click the button. > > I haven''t found relevant information in google. > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
<HTML> <HEAD> <script type="text/javascript"> function validate(){ if(document.getElementById(''first_name'')=="") alert("First name can''t be blank"); } </script> </HEAD> <BODY> <% form_tag({:action => "create"}, {:onsubmit => "return validate();"}) %> First name: <input type="text" name="first_name" id="first_name"> <% end %> </BODY> </HTML> I hope it will help On Wed, Sep 9, 2009 at 2:31 PM, HUNT HUNT <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > I put the code but the result coming is that no action is performed on > click the button. > > I haven''t found relevant information in google. > -- > Posted via http://www.ruby-forum.com/. > > > >-- Thanks and Regards ___________________ Puneet Pandey Ruby on Rails Developer http://www.puneetitengineer.wordpress.com In Puneet''s Lab: http://www.puneetpandey.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 -~----------~----~----~----~------~----~------~--~---
Hey Puneet, The code which u send I tried with that......it is not validating instead it goes blank page saying undefined template. THanks Hunt -- Posted via http://www.ruby-forum.com/.
<HTML> <HEAD> <script type="text/javascript"> function validate(){ if($(''search'').value==''''){ alert("Please enter keyword(s) to search."); return false; } else{ return true; } } </script> </HEAD> <BODY> <% form_tag ({:action=>''create''}, {:onsubmit=>''return validate()''}) do %> <input type="text" name="search" id="search"> <% end %> </BODY> </HTML> I am sure this time it will surely help you On Wed, Sep 9, 2009 at 5:01 PM, HUNT HUNT <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > > > Hey Puneet, The code which u send I tried with that......it is not > validating > instead it goes blank page saying undefined template. > > THanks > Hunt > -- > Posted via http://www.ruby-forum.com/. > > > >-- Thanks and Regards ___________________ Puneet Pandey Ruby on Rails Developer http://www.puneetitengineer.wordpress.com In Puneet''s Lab: http://www.puneetpandey.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 -~----------~----~----~----~------~----~------~--~---
Tried again, this time the output is a new page with Unknown action No action responded to create. can see the attached file.............. Attachments: http://www.ruby-forum.com/attachment/4020/Screenshot.png -- Posted via http://www.ruby-forum.com/.
Error says it all: you do not have "create" action in your controller. Add it, it''s not a javascript issue anymore. Thanks, Abhinav -- अभिनव http://twitter.com/abhinav On Wed, Sep 9, 2009 at 5:29 PM, HUNT HUNT<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Tried again, > > this time the output is a new page with > > Unknown action > > No action responded to create. > > > can see the attached file.............. > > > Attachments: > http://www.ruby-forum.com/attachment/4020/Screenshot.png > > -- > Posted via http://www.ruby-forum.com/. > > > >
Dude your javascript is not getting loaded when your submit button is pressed.. look carefully when you are calling javascript.. try to alert some text to see what''s going wrong there On Wed, Sep 9, 2009 at 5:29 PM, HUNT HUNT <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > Tried again, > > this time the output is a new page with > > Unknown action > > No action responded to create. > > > can see the attached file.............. > > > Attachments: > http://www.ruby-forum.com/attachment/4020/Screenshot.png > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Thanks and Regards ___________________ Puneet Pandey Ruby on Rails Developer http://www.puneetitengineer.wordpress.com In Puneet''s Lab: http://www.puneetpandey.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 -~----------~----~----~----~------~----~------~--~---
Abhinav Saxena wrote:> Error says it all: you do not have "create" action in your controller. > Add it, it''s not a javascript issue anymore. > > Thanks, > Abhinav > -- > अभिनव > http://twitter.com/abhinav > > > > > On Wed, Sep 9, 2009 at 5:29 PM, HUNTI haven''t created any action in the controller........ -- Posted via http://www.ruby-forum.com/.
Interestingly, the browser apparently can load the page quicker if javascript is at the bottom. http://developer.yahoo.com/performance/rules.html -Jim http://www.thepeoplesfeed.com On Wed, Sep 9, 2009 at 5:08 AM, Abhinav Saxena <abhinav061-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ideally, javascript should be kept in head section of html, and for this > you can use content_for tag. Read more about here: > http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#M001763 > > Thanks, > Abhinav > -- > अभिनव > http://twitter.com/abhinav > > > > On Wed, Sep 9, 2009 at 2:31 PM, HUNT HUNT < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> >> I put the code but the result coming is that no action is performed on >> click the button. >> >> I haven''t found relevant information in google. >> -- >> 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Englert wrote:> Interestingly, the browser apparently can load the page quicker if > javascript is at the bottom. > > http://developer.yahoo.com/performance/rules.html >That''s a bizarre set of recommendations, especially given that Doug Crockford, Yahoo!''s own JS architect, recommends that JS not be mixed in with HTML at all.> -Jim > http://www.thepeoplesfeed.comBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
On Wed, Sep 9, 2009 at 12:21 PM, Marnen Laibow-Koser<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > James Englert wrote: >> Interestingly, the browser apparently can load the page quicker if >> javascript is at the bottom. >> >> http://developer.yahoo.com/performance/rules.html >> > > That''s a bizarre set of recommendations, especially given that Doug > Crockford, Yahoo!''s own JS architect, recommends that JS not be mixed in > with HTML at all.Other than one specific case of a certain kind of landing page, I don''t see a recommendation there to mix javascript and html. They recommend combining multiple script resources into one, minifying etc. I take putting the javascript at the bottom as putting the script tags referencing the separate script resource(s) at the bottom not inlining javascript in the page. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale