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:
28
form.php
28
form.php
@@ -221,19 +221,33 @@ class form
|
|||||||
|
|
||||||
// Manage the focus. On the first visible element if there is no error, on
|
// Manage the focus. On the first visible element if there is no error, on
|
||||||
// the first error fields when there is one
|
// the first error fields when there is one
|
||||||
|
$focusElement = null;
|
||||||
foreach ($this->fields as $field)
|
foreach ($this->fields as $field)
|
||||||
{
|
{
|
||||||
if ($field->type !== "hidden" && $field->readonly !== true)
|
if ($field->type === "hidden" || $field->readonly === true)
|
||||||
break;
|
continue;
|
||||||
|
$focusElement = $field->name;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$focusElement = $field->name;
|
|
||||||
if (count ($errors) > 0)
|
if (count ($errors) > 0)
|
||||||
{
|
{
|
||||||
reset ($errors);
|
foreach ($errors as $fieldErr=>$error)
|
||||||
$focusElement = key ($errors);
|
{
|
||||||
|
// 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."_".
|
if ($focusElement !== null)
|
||||||
$focusElement."').focus();</script>\n";
|
$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