[Pieforms-commit] SF.net SVN: pieforms: [268] pieforms-php5/trunk/src/static/core/pieforms.js
Status: Alpha
Brought to you by:
oracleshinoda
From: <ora...@us...> - 2007-12-31 12:16:36
|
Revision: 268 http://pieforms.svn.sourceforge.net/pieforms/?rev=268&view=rev Author: oracleshinoda Date: 2007-12-31 04:16:36 -0800 (Mon, 31 Dec 2007) Log Message: ----------- Now pieforms.js will focus things that require focusing on page load, and when forms are submitted it will update what is focused. This works even when there is more than one form on the page - the code will work out the correct element to focus. Modified Paths: -------------- pieforms-php5/trunk/src/static/core/pieforms.js Modified: pieforms-php5/trunk/src/static/core/pieforms.js =================================================================== --- pieforms-php5/trunk/src/static/core/pieforms.js 2007-12-31 12:16:11 UTC (rev 267) +++ pieforms-php5/trunk/src/static/core/pieforms.js 2007-12-31 12:16:36 UTC (rev 268) @@ -83,6 +83,7 @@ replaceChildNodes($(self.data.name), tmp.childNodes[0].childNodes); self.connectSubmitButtons(); + pieformSetFocus(); if (data.returnCode == 0) { // Call the defined success callback, if there is one @@ -158,6 +159,22 @@ addLoadEvent(self.init); } +function pieformSetFocus() { + var check = getElementsByTagAndClassName('form', 'pieform'); + var formsWithError = filter(function(i) { return hasElementClass(i, 'error'); }, check); + if (formsWithError.length > 0) { + check = formsWithError; + } + forEach(check, function(form) { + var element = getFirstElementByTagAndClassName(null, 'autofocus', form); + if (element && typeof(element.focus) == 'function') { + element.focus(); + throw MochiKit.Iter.StopIteration; + } + }); +} +addLoadEvent(pieformSetFocus); + // The resizable textarea code is based on the code from Drupal (http://drupal.org/) /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |