Hi,
I'm playing around with validation and ajax, and can't quite seem to do
what I want. The goal is to have a checkbox toggle enabled/disabled
depending on whether the user has entered a valid email address. So, my
simple test looks like this:
------------------
final TextField<String> fromAddress = new TextField<String>("fromAddress");
fromAddress.add(EmailAddressValidator.getInstance());
fromAddress.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
if (fromAddress.isValid()) {
System.out.println("valid");
} else {
System.out.println("not valid");
}
}
}.setThrottleDelay(Duration.ONE_SECOND));
----------------
If the entered address is valid, then I do get the expected output "valid"
But if it's not valid, then I get a warning message:
--------------
WARN - WebSession - Component-targetted feedback
message was left unrendered. This could be because you are missing a
FeedbackPanel on the page. Message: [FeedbackMessage message =
"'asd...@l' is not a valid email address.", reporter = fromAddress,
level = ERROR]
------------
I do have a feedbackpanel on the page (if I submit the form, then I get
the "asd...@l is not a valid email address" output there).
However, I really don't want the error message being output during the
ajax process, I just want to see if it's valid, and then enable/disable
the checkbox accordingly.
I also tried playing with AjaxEventBehavior instead of
AjaxFormComponentUpdatingBehavior, but then the value of the input field
always is null, and hence valid :) I tried using
fromAddress.inputChanged, but that made no difference that I could see.
I'm sure I'm making some stupid mistake. Can anyone guide me in the
right direction?
/Stefan