form : If the error is not due to field (it has numerical key, put the focus on the first field (if available) and not on the global error

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3562 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2017-05-02 14:17:46 +00:00
parent 029bb0beb5
commit 0d63ce1e34

View File

@@ -221,19 +221,33 @@ class form
// Manage the focus. On the first visible element if there is no error, on
// the first error fields when there is one
$focusElement = null;
foreach ($this->fields as $field)
{
if ($field->type !== "hidden" && $field->readonly !== true)
break;
if ($field->type === "hidden" || $field->readonly === true)
continue;
$focusElement = $field->name;
break;
}
$focusElement = $field->name;
if (count ($errors) > 0)
{
reset ($errors);
$focusElement = key ($errors);
foreach ($errors as $fieldErr=>$error)
{
// If the field is numeric, it is a global error, and not an error due
// to a field: skip it !
foreach ($this->fields as $field)
{
if ($field->name === $fieldErr)
{
$focusElement = $field->name;
break 2;
}
}
}
}
$res .= "<script>document.getElementById('".$this->formName."_".
$focusElement."').focus();</script>\n";
if ($focusElement !== null)
$res .= "<script>document.getElementById('".$this->formName."_".
$focusElement."').focus();</script>\n";
$res .= "</form>\n";
return $res;
}