Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Fields in a form that have errors lose focus on first key press

    Fields in a form that have errors lose focus on first key press.

    For example I have a form with 2 required fields, email and username, in that order. The email field also does regexp validation to enforce the email format. When I submit with both fields empty, they both get validation errors as expected. But when I try to fix email, as soon as I type a character the focus jumps to the next field with an error, username. Focus only stays in email after username is corrected. Then I can fix email as expected.

    I hope that is a clear description.
    Why does focus jump to the next error field on first key press?
    Am I missing a configuration or something?

    My form creation is very simple...
    Code:
    final DynamicForm form = new DynamicForm();
    form.setDataSource(DataSource.get(DATA_SOURCE));
    form.setFields(new FormItem("email"), new FormItem("username"));
    thanks
    ,chris
    (SGWT EE 2.5 eval)

    #2
    This would happen if you had configured form-wide validation to run on every keystroke, since focus will jump to the first item that has an error. A combination of, for example, validateOnChange plus changeOnKeypress could do this.

    Comment


      #3
      OK. Fixed it. I had set the default for all forms to setValidateOnChange(true). Now it is setValidateOnExit(true) and I get the behavior I want.

      Thanks!
      ,chris

      Comment

      Working...
      X