Skip to content

Instantly share code, notes, and snippets.

@dmoulton
Created May 17, 2012 18:58
Show Gist options
  • Save dmoulton/2720909 to your computer and use it in GitHub Desktop.
Save dmoulton/2720909 to your computer and use it in GitHub Desktop.
Rails helper for tab order in forms
# 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