This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to focus on error field

 
Vipin Sahu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using validator framework and it is working fine. But is there any way to focus the cursor on the error field in struts. And how can we display only one error at a time.
Please help me!
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vipin Sahu:
is there any way to focus the cursor on the error field in struts.

Yes, with a combination of Javascript and the <logic:messagesPresent>. Just specify an onload event in the <body> tag that references a JavaScript function. Then in that function, code something like this:

If fields A, B, and C all have errors, focus will be on FieldC since it's the last in the list. You therefore might want to put the conditions in the reverse order of how they appear on the screen. That way the top field on the screen that has an error will get the focus.
Originally posted by Vipin Sahu:
how can we display only one error at a time.

You do this using the property attribute. If you want a separate field that only shows errors for fieldA, specify the following:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic