Created
May 17, 2012 18:58
-
-
Save dmoulton/2720909 to your computer and use it in GitHub Desktop.
Rails helper for tab order in forms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Should probably go in application_helper | |
# examples (when run in this order): | |
# autotab # returns 1 | |
# autotab # returns 2 | |
# autotab(100) # returns 102 | |
# autotab # returns 3 | |
# autotab(100,true) # returns 104 | |
# autotab # returns 105 | |
# example f.text_field :address, :tabindex=>autotab | |
def autotab(offset=nil,update=false) | |
@current_tab ||= 0 | |
if offset.nil? | |
ret = @current_tab += 1 | |
elsif update | |
ret = @current_tab += offset | |
else | |
ret = @current_tab + offset | |
end | |
ret | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment