Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Tab order" in a rails app

In a rails app, I want users to be able to enter data without having to use a mouse.

To help do this, I want to set the order in which the cursor moves to text fields, drop-down boxes, and buttons.

Is there a way to do this?

like image 952
inglesp Avatar asked Apr 21 '09 13:04

inglesp


People also ask

What does Tabindex =- 1 mean?

A negative value (usually tabindex="-1" ) means that the element is not reachable via sequential keyboard navigation, but could be focused with JavaScript or visually by clicking with the mouse. It's mostly useful to create accessible widgets with JavaScript.

What is the difference between Tabindex 0 and Tabindex =- 1?

tabindex="1" (or any number greater than 1) defines an explicit tab or keyboard navigation order. This must always be avoided. tabindex="0" allows elements besides links and form elements to receive keyboard focus.


2 Answers

Jeff Peterson is almost right.

<%= f.text_field :attribute, :tabindex => 1 %>
like image 116
Mikkel Paulson Avatar answered Sep 21 '22 22:09

Mikkel Paulson


<%= f.text_field :attribute, :tabindex => 1 %>

then 2, 3, 4, etc.

Edit: Removed underscore from "tab_index". So close.

Also, you can make a helper method to automatically increment the index:

def tabindex
  @tabindex ||= 0
  @tabindex += 1
end
like image 38
Jeff Peterson Avatar answered Sep 25 '22 22:09

Jeff Peterson