wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Igor Vaynberg <igor.vaynb...@gmail.com>
Subject Re: ajaxformcomponent
Date Wed, 01 Jul 2009 16:46:45 GMT
my point was that what you want is equivalent to

final TextField<String> fromAddress = new TextField<String>("fromAddress");
fromAddress.add(EmailAddressValidator.getInstance());

       fromAddress.add(new AjaxFormComponentUpdatingBehavior("onchange") {

           @Override
           protected void onUpdate(AjaxRequestTarget target) {
                   System.out.println("valid!");
           }

           @Override
           protected void onError(AjaxRequestTarget target) {
                   System.out.println("not valid!");
           }

       }.setThrottleDelay(Duration.ONE_SECOND));

-igor

2009/7/1 Stefan Malmesjö <s.m.mogul@gmail.com>:
> Because I'm stubborn, and wanted to get the "send" button (and a checkbox)
> enabled via ajax only when the user has entered the right data in the form.
>
> The only way I seem to be able to do that is in the way below.
>
> But on the other hand I'm starting to think that might not be a good way to
> do things. The user gets no real good feedback as to *why* the
> button/checkbox is not enabled if I do it that way...
>
> /Stefan
>
> On 2009-07-01 16:55, Igor Vaynberg wrote:
>>
>> not sure why you are going through all that. add the validator.
>> behavior#onupdate() will be called when validation passes and the
>> model is updated, behavior#onerror() will be called if there is an
>> error.
>>
>> -igor
>>
>> 2009/7/1 Stefan Malmesjö<s.m.mogul@gmail.com>:
>>
>>>
>>> Ok... I think I solved it, but it feels like it's an over complicated way
>>> of
>>> doing it... comments?
>>>
>>> -------------------
>>> final TextField<String>  fromAddress = new
>>> TextField<String>("fromAddress");
>>>        // fromAddress.add(EmailAddressValidator.getInstance());
>>>
>>>
>>>
>>>        fromAddress.add(new AjaxFormComponentUpdatingBehavior("onchange")
>>> {
>>>
>>>            @Override
>>>            protected void onUpdate(AjaxRequestTarget target) {
>>>                IValidatable<String>  fromAddressForValidation
= new
>>> IValidatable<String>() {
>>>                    private boolean isValid = true;
>>>
>>>                    public void error(IValidationError error) {
>>>                        isValid = false;
>>>                    }
>>>
>>>                    public String getValue() {
>>>                        return fromAddress.getValue();
>>>                    }
>>>
>>>                    public boolean isValid() {
>>>                        return isValid;
>>>                    }
>>>                };
>>>                EmailAddressValidator.getInstance()
>>>                    .validate(fromAddressForValidation);
>>>                if (fromAddressForValidation.isValid()) {
>>>                    System.out.println("valid!");
>>>                } else {
>>>                    System.out.println("not valid");
>>>                }
>>>            }
>>>        }.setThrottleDelay(Duration.ONE_SECOND));
>>>
>>>
>>> -------------------
>>>
>>> On 2009-06-30 18:15, Stefan Malmesjö wrote:
>>>
>>>>
>>>> The subject should have been AjaxFormComponentUpdatingBehavior... sorry
>>>> about that :-[
>>>>
>>>> On 2009-06-30 18:12, Stefan Malmesjö wrote:
>>>>
>>>>>
>>>>> 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 = "'asdsfg@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 "asdsfg@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
>>>>>
>>>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Mime
View raw message