Skip to content

Instantly share code, notes, and snippets.

@cacheflowe
Created November 19, 2013 16:20
Show Gist options
  • Save cacheflowe/7547942 to your computer and use it in GitHub Desktop.
Save cacheflowe/7547942 to your computer and use it in GitHub Desktop.
CoffeeScript: Confine form input tabbing to a group of inputs
disableForms: (page) ->
@formInputs = page.$el.find('input[tabindex], textarea[tabindex]')
@formInputs.off 'keydown', @handleTab
@formInputs.blur()
enableForms: (page) ->
@formInputs = page.$el.find('input[tabindex], textarea[tabindex]')
@formInputs.on 'keydown', @handleTab
handleTab: (e) =>
if e.keyCode == 9
e.preventDefault();
for i in [[email protected]] by 1
if @formInputs[i] == e.target
$(@formInputs[(i+1)%@formInputs.length]).focus()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment