I have this text field that once a certain number of character are entered I would like it to call a method in the controller and save the data. To make a long story short, I do this because I don''t want the user to hit a button to submit, but want this to be a quick edit option for entering a telephone number. What I am doing is to check the number of character in my javascript, if the length equals the max I would like my method call to happen. Is there a way to call a controller method from a javascript method? 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 have this text field that once a certain number of character are > entered I would like it to call a method in the controller and save the > data. To make a long story short, I do this because I don''t want the > user to hit a button to submit, but want this to be a quick edit option > for entering a telephone number. > > What I am doing is to check the number of character in my javascript, if > the length equals the max I would like my method call to happen. Is > there a way to call a controller method from a javascript method? > Thanks, > > -SI just did something like this today. In my case, when a certain event happens, I fire off an AJAX call to update a session variable. Here''s how I did it: In my event code, I included a call to this function function sidebar_menu_store_state(menu_id, expanded) { new Ajax.Request(''/person/store_sidebar_menu_state'', { method: ''post'', parameters: { menu_id: menu_id, expanded: expanded } }); } then in my controller, I have def store_sidebar_menu_state return unless request.xhr? return unless request.post? [do the logic] render :nothing => true end # store_sidebar_menu_state There is probably a much better way to do it, but this works well for what I need it to do. So if you already have the character count happening, all you''d have to do is tack on the logic to hit the server once the max is encountered. I might add, though, that you could accomplish the same thing in an onblur. When the user finishes typing in the text and focus leaves the field, update the database. Peace, Phillip -- 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 -~----------~----~----~----~------~----~------~--~---
On Wed, May 7, 2008 at 1:27 PM, Phillip Koebbe <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I might add, though, that you could accomplish the same thing in an > onblur. When the user finishes typing in the text and focus leaves the > field, update the database....which is probably better, or at least more universal, since a "phone number" can be an arbitrary number of digits. :-) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Phillip Koebbe wrote:> > I might add, though, that you could accomplish the same thing in an > onblur. When the user finishes typing in the text and focus leaves the > field, update the database. > > Peace, > PhillipThis is what I ended up doing and then submitting the data with a remote_function call. 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 -~----------~----~----~----~------~----~------~--~---