Pylons/deform — pull request #244 by nullcipher (2014-10-11 09:55:42+00:00)
Title: Selectable autofocus

I came across an issue when building a site with a responsive layout.

The issue is this:

deform.js runs focusFirstInput() on document.ready().

If a form is below the fold, the browser scrolls to the element which has received focus. This is usually not a problem, as most forms are above the fold. However, responsive layouts can push forms below the fold on small devices. The end result being, a user loads the page and is immediately scrolled down to wherever the form is.

A solution is to overload the deform.load method, but this doen't work reliably if javascript is loaded asynchronously. The solution I have been using is in this (selectable_autofocus) branch.

An autofocus parameter was added. Forms can be init-ed with autofocus=False. This will result in a data-autofocus='off' attribute being added to the form. The focusFirstInput() function of deform.js was altered to ignore forms with data-autofocus='off' attributes.

The end result is:
* Default behaviour is unchanged.
* A switch is available to turn off automatic focusing on a per-form basis.
* data-* attributes validate