Does anyone know how to set the mouse curser in a text box/area. For example: When a user is presented with a form - I want the mouse curser positioned in the first form item. Another example - I want to create a wiki-style text area where users can add formatting by clicking a button (think TRAC) When a user clicks the bold button, for example, the bold markup will display in the text area with the mouse positioned between the mark-up. Know how to do this? Thanks in advance. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Kim wrote:> Does anyone know how to set the mouse curser in a text box/area. For > example: > > When a user is presented with a form - I want the mouse curser > positioned in the first form item. > > Another example - I want to create a wiki-style text area where users > can add formatting by clicking a button (think TRAC) When a user clicks > the bold button, for example, the bold markup will display in the text > area with the mouse positioned between the mark-up. > > Know how to do this? Thanks in advance.Rails has no built in way of doing this (that I know of), but it is easily achieved with simple javasripts. -- 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 -~----------~----~----~----~------~----~------~--~---
augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-20 13:35 UTC
Re: Position Mouse Curser - RoR way
The RoR way of doing this is not to do it. Users would hate it, and it''s very not-RoR. On Jan 20, 2:33 am, Andrew Skegg <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Kim wrote: > > Does anyone know how to set the mouse curser in a text box/area. For > > example: > > > When a user is presented with a form - I want the mouse curser > > positioned in the first form item. > > > Another example - I want to create a wiki-style text area where users > > can add formatting by clicking a button (think TRAC) When a user clicks > > the bold button, for example, the bold markup will display in the text > > area with the mouse positioned between the mark-up. > > > Know how to do this? Thanks in advance.Rails has no built in way of doing this (that I know of), but it is > easily achieved with simple javasripts. > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
why would you need the pointer positioned over a form field? i can''t see how that would serve any kind of purpose. now, if you really mean you want the first form element to have focus, that''s quite different and is used quite often. if using the prototype library, just give your form input elements an id (if you are using rails helper methods to generate input fields, this will already be done for you) <script type="text/javascript"> Field.focus(''id_of_element_you_want_focused_at_page_load''); </script> make sure to put this somewhere after the form itself. for extra credit, add a class name to your fields and when the field is focused it will stand out more. in your css add something like .field:focus { background-color: #ffffcc; } i believe that will work across all browsers ( i know safari and firefox handle it ok ). On 1/20/07, augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > The RoR way of doing this is not to do it. Users would hate it, and > it''s very not-RoR. > > On Jan 20, 2:33 am, Andrew Skegg <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > Kim wrote: > > > Does anyone know how to set the mouse curser in a text box/area. For > > > example: > > > > > When a user is presented with a form - I want the mouse curser > > > positioned in the first form item. > > > > > Another example - I want to create a wiki-style text area where users > > > can add formatting by clicking a button (think TRAC) When a user clicks > > > the bold button, for example, the bold markup will display in the text > > > area with the mouse positioned between the mark-up. > > > > > Know how to do this? Thanks in advance.Rails has no built in way of doing this (that I know of), but it is > > easily achieved with simple javasripts. > > > > -- > > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Yes, what I want is to have the curser pre-positioned in the first field - focus will do it. Thanks On Jan 20, 9:17 am, "Chris Hall" <christopher.k.h...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> why would you need the pointer positioned over a form field? i can''t > see how that would serve any kind of purpose. > > now, if you really mean you want the first form element to have focus, > that''s quite different and is used quite often. > > if using the prototype library, just give your form input elements an > id (if you are using rails helper methods to generate input fields, > this will already be done for you) > > <script type="text/javascript"> > Field.focus(''id_of_element_you_want_focused_at_page_load''); > </script> > > make sure to put this somewhere after the form itself. > > for extra credit, add a class name to your fields and when the field > is focused it will stand out more. > > in your css add something like > > .field:focus { > background-color: #ffffcc; > > }i believe that will work across all browsers ( i know safari and > firefox handle it ok ). > > On 1/20/07, augustlille...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <augustlille...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > The RoR way of doing this is not to do it. Users would hate it, and > > it''s very not-RoR. > > > On Jan 20, 2:33 am, Andrew Skegg <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > Kim wrote: > > > > Does anyone know how to set the mouse curser in a text box/area. For > > > > example: > > > > > When a user is presented with a form - I want the mouse curser > > > > positioned in the first form item. > > > > > Another example - I want to create a wiki-style text area where users > > > > can add formatting by clicking a button (think TRAC) When a user clicks > > > > the bold button, for example, the bold markup will display in the text > > > > area with the mouse positioned between the mark-up. > > > > > Know how to do this? Thanks in advance.Rails has no built in way of doing this (that I know of), but it is > > > easily achieved with simple javasripts. > > > > -- > > > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
> > <script type="text/javascript"> > > Field.focus(''id_of_element_you_want_focused_at_page_load''); > > </script> > > > > make sure to put this somewhere after the form itself.I can not get this to work - can you provide an example? Can''t I put this in the JS files so it does not have to be on every form, and then call the field id in each form that I want to have the focus a common name? Thanks, K --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
example: <html> <head> <%= javascript_include_tag "prototype %> </head> <body> <form method="post" action="..."> <input type="text" name="field1" id="field1"/> <input type="submit" name="Save"/> </form> <script type="text/javascript"> Field.focus(''field1''); </script> </body> </html> On 1/22/07, Kim <Kim.Griggs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > > <script type="text/javascript"> > > > Field.focus(''id_of_element_you_want_focused_at_page_load''); > > > </script> > > > > > > make sure to put this somewhere after the form itself. > > I can not get this to work - can you provide an example? Can''t I put > this in the JS files so it does not have to be on every form, and then > call the field id in each form that I want to have the focus a common > name? >there''s nothing stopping you from doing that, no. but i fail to see the reason why. you still have to have a line of javascript in your template in order to actually focus the element. if you put it in a separate file, that file has to be loaded off the server, vs. having it inline. also (not sure about this), i''d be concerned about how the browser loads external files and to when they are interpreted. ie, is it going to load/interpret that js file prior to rendering the form? focus.js ---- snip ----- Field.focus(''element_id''); ---- snip ----- template ---- snip ----- <script src="/javascripts/focus.js"/> ---- snip ----- vs. <script type="text/javascript"> Field.focus(''element_id''); </script>> Thanks, K > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the example - but not applicable - I am not using prototype. Here is what I have tried - still not working. start_form_tag :action => ''register'', :id => @user <label for="user_email">Email</label> text_field ''user'', ''email'' submit_tag ''Register'' end_form_tag <script type="text/javascript"> Field.focus(''user_email''); </script> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
well your choices are: 1) use prototype javascript library (it''s installed as a part of every new rails project) 2) use the base javascript functionality to apply focus to a form element. there are a myriad of samples/tutorials on the web at your disposal. On 1/22/07, Kim <Kim.Griggs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Thanks for the example - but not applicable - I am not using prototype. > Here is what I have tried - still not working. > > start_form_tag :action => ''register'', :id => @user > <label for="user_email">Email</label> > text_field ''user'', ''email'' > submit_tag ''Register'' > end_form_tag > > <script type="text/javascript"> > Field.focus(''user_email''); > </script> > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---