Hi Cristophe,

Thank you for that trick! As beginner in JavaScript didn't know that I 
can use tabIndex from JS to find a next element to tab into.

Anyway, because I have control on tabulation order on server I decided 
to let the server write a script to tab into a right next element. This 
is still better because I think have more control on tabulation than 
from JS.

Best regards
Janko

Christophe Porteneuve wrote:
> Hey Janko,
> 
> If you're fully in control of your HTML, you can leverage the tabindex
> attribute, and create a generic handler, something like:
> 
> <form id="inputForm"...>
>   ...
>   <input type="text"... tabindex="1" />
>   ...
>   <input type="text"... tabindex="2" />
>   ...
> </form>
> 
> And then in your JS (untested, but should work):
> 
> function grabEnterAndTabOver(e) {
>   var elt = Event.element(e);
>   if (elt.tagName != 'INPUT' || elt.type != 'text')
>     return;
>   var ti = elt.tabIndex;
>   var elts = $$('#inputForm input[tabindex=' + (ti + 1) + ']');
>   if (elts.length > 0) {
>     Event.stop(e);
>     elts.first().activate();
>   }
> } // grabEnterAndTabOver
> 
> Event.observe('inputForm', 'keypress', grabEnterAndTabOver);
> 
> This reacts to Return to tab to the next (tabindex-wise) element in the
> form, then goes to it.  If you can't find the tabindex you're looking
> for, you leave the Return key to its default processing.
> 
> You can make it generic by using $(elt).up('form').id to grab the parent
> form's ID, or even by not using $$ but using this on the so-obtained
> form reference:
> 
>       getInputs('text').find(function(elt) {
>           return elt.tabIndex == ti + 1; });
> 
> There are many ways...  The point is: tabindex is there to define
> specific tab navigation rules, so leverage it!
> 

-- 
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to