You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Vance Heredia <Va...@lonelyplanet.com.au> on 2003/08/11 05:04:21 UTC

How to return to form element

I use the Action Errors to validate a form.  

If I do find errors does anyone know how to set the focus to the first
eroneous field present on the form when it returns to it ???

Vance

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Vance Heredia
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

______________________________________________________________________
This email, including attachments, is intended only for the addressee
and may be confidential, privileged and subject to copyright.  If you
have received this email in error, please advise the sender and delete
it.  If you are not the intended recipient of this email, you must not
use, copy or disclose its content to anyone.  You must not copy or 
communicate to others content that is confidential or subject to 
copyright, unless you have the consent of the content owner.

RE: How to return to form element

Posted by Steve Vanspall <st...@crmsoftware.com.au>.
Well I dont know of any easy way to do it

but you could probably make use of the action errors somehow.

maybe create, in your message resurces file, a piece of javascript that
dynamically set the name of the field to be focused on. Then the onload
function would focus on it for you. Sounds a bit complicated but would go
something like this.

-- if form validate --
boolean firstField = true;
if(myField == null)
{
	if(firstField)
	{
		errors.add("javascriptErrors", new ActionError("error.js.field.missing",
fieldName));
		firstField = false;
	}

}

-- in message resources --

error.js.field.missing = <script>focusField = {0}</script>

-- in page --
<script>
var focusFiled = null;
</script>

<body onload="if(focusField != null) document.all[focusField].focus;">

<html:errors property="javascriptErrors"/>



That's if you're making use of the message resources feature.

Just one possible suggestion

Steve


-----Original Message-----
From: Vance Heredia [mailto:Vance.Heredia@lonelyplanet.com.au]
Sent: Monday, 11 August 2003 1:04 PM
To: 'struts-user@jakarta.apache.org'
Subject: How to return to form element



I use the Action Errors to validate a form.

If I do find errors does anyone know how to set the focus to the first
eroneous field present on the form when it returns to it ???

Vance

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Vance Heredia
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

______________________________________________________________________
This email, including attachments, is intended only for the addressee
and may be confidential, privileged and subject to copyright.  If you
have received this email in error, please advise the sender and delete
it.  If you are not the intended recipient of this email, you must not
use, copy or disclose its content to anyone.  You must not copy or
communicate to others content that is confidential or subject to
copyright, unless you have the consent of the content owner.


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org