We use a lot of validators on TextField.
In the beta release they are only called when the TextInputCell lose ther focus.
This makes a Validator pretty useless.
Try textField.setAutoValidate(true) when using the field to make it validate after each key. By default fields do not validate until blur - why tell the user they are already wrong when they haven't finished yet?
why tell the user they are already wrong when they haven't finished yet?
When the validation is not intrusive (just a hint), I find the technique useful. For example, if the user types letters in a numbers-only text field, it is better to warn early. For example, in my (desktop) text editor, sometime I hit Ctrl+G (go to line number) instead of Ctrl+F (find) and I am happy not to type a whole string before being warned it is useless...
Do you think also about asynchronous validating process ? After blur field shall lock (pending state) and start ex. remote value test (via rpc). After receiving the response callbck should continue to validate.
Two possibilities for validating. If you are validating an entire form, editing an object with GWT's Editor drivers, use the EditorDriver.setConstraintViolations method, which will pass the errors on down to the fields to show the issue (this can be seen at http://www.sencha.com/examples-dev/#...factorybinding by leaving the name field blank and clicking save). You can use JSR 303 validations on your server, or you can build some class which implements the ConstraintViolation interface. As a third option, GWT provides the static method SimpleViolation.simpleViolations with the easier to implement SimpleViolation abstract class. If you are already using the Editor framework, this is almost certainly the correct choice.
The second possibility is to call one of the Field methods to assign a error manually. The first of these is Field.forceInvalid method: this can be called at any time to force a field to be invalid. As the javadoc describes, this will not be cleared as a result of the user entering more data. The second is Field.markInvalid, which may be cleared as soon as validation occurs again. In either case, I would suggest attaching a handler on the ValueChangeEvent to start validation instead of implementing the Validator interface, which is meant to be used synchronously.