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?
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.
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.
Jeff Peterson is almost right.
<%= f.text_field :attribute, :tabindex => 1 %>
<%= 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With