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:
15
form.php
15
form.php
@@ -212,6 +212,21 @@ class form
|
|||||||
$res .= $csrf->displayFormCSRF ();
|
$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";
|
$res .= "</form>\n";
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user