2

I'm getting started with Struts 2 and I am trying to validate 2 text fields using Struts xml validators.

<s:textfield name="userName" id="userName" label="User Name">
<s:textfield name="passWord" id="userName" label="Password">

I was able to validate fields by clicking submit button.

Is it possible to validate fields even before clicking submit button? Conditions would be: when you try to enter password without userName, validate userName field and display error message if it's empty.

any help would appreciated.

Snakes and Coffee
  • 8,747
  • 4
  • 40
  • 60
GoodFellaa
  • 21
  • 1

2 Answers2

0

You'll have to do it before the request, that is, on the client side. You could use Javascript with a OnChange or OnKeyDown event on the textboxes. The triggered method could invalidate the submission and display error messages using DOM. Just by curiosity, why would you need to do this exactly ?

Tom11
  • 2,419
  • 8
  • 30
  • 56
LMeyer
  • 2,570
  • 1
  • 24
  • 35
0
Regarding this question in stack overflow so many discussions are already there (but not   in strtus2  it is in JQuery).

I am giving those links you can refer it from here,
How do I use jQuery Validate directly, without the submit button

jquery validate: IF form valid then show submit button

Hide submit button until form is valid

Community
  • 1
  • 1
Raki
  • 361
  • 2
  • 13