[Seaside] Setting focus on Input field in form
Lukas Renggli
renggli at student.unibe.ch
Wed Mar 17 08:08:40 CET 2004
> It looks like there is often a hidden input control defined first in
> the
> sequence input fields. Are hidden input controls returned in the
> elements array?
Yes definitely, hidden fields are also returned in this sequence,
because there are many other things you could do with them than calling
"Element>>focus()".
> BTW, a reason that I don't always want to use the first element is that
> I return to the page when errors occur and want focus on another
> element
> based on where the first error occurred. I'm modifying my system to
> handle this case right now.
Ok, I see this gets a bit more complicated: if I were you I would
either try to avoid rendering hidden-fields before the visible controls
or write some kind of #at: function ignoring hidden fields:
function getVisibleFormElement(form_index, element_index) {
index = 0;
form = document.forms[form_index];
for (i = 0; i < form.elements.length; i++) {
if (form.elements[i].type != "hidden") {
if (index == element_index)
return form.elements[i];
index++;
}
}
return NULL;
}
As usual, I haven't tested the above code and it should be also
possible to put it somehow into the existing prototype of form (what
would be more elegant), but I don't remember how to archive this.
Cheers,
Lukas
--
Lukas Renggli
http://renggli.freezope.org
More information about the Seaside
mailing list