From 3a635ce39a57474b1fb75c3ec0d4cba15e971165 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Tue, 23 Feb 2016 08:53:30 +0000 Subject: [PATCH] form : add the javascript to focus on the first field if there is no error, or on the first error when there is one git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2534 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- form.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/form.php b/form.php index 92cd86c..e5a7815 100644 --- a/form.php +++ b/form.php @@ -212,6 +212,21 @@ class form $res .= $csrf->displayFormCSRF (); } + // Manage the focus. On the first visible element if there is no error, on + // the first error fields when there is one + foreach ($this->fields as $field) + { + if ($field->type !== "hidden") + break; + } + $focusElement = $field->name; + if (count ($errors) > 0) + { + reset ($errors); + $focusElement = key ($errors); + } + $res .= "\n"; $res .= "\n"; return $res; }