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
This commit is contained in:
2016-02-23 08:53:30 +00:00
parent 2e64755481
commit 3a635ce39a

View File

@@ -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 .= "<script>document.getElementById('".$this->formName."_".
$focusElement."').focus();</script>\n";
$res .= "</form>\n";
return $res;
}