there is ajaxformsubmitbehavior if you want all the fields updated

-igor

On Wed, Apr 21, 2010 at 6:10 AM, Steven Haines <lyg...@yahoo.com> wrote:
> Hi Igor,
>
> I looked at the JavaScript that is generated when adding an 
> AjaxFormComponentUpdatingBehavior and it does not include any form fields 
> other than the component to which it is added:
>
> onChange="if(this.value.length >= 5){var 
> wcall=wicketAjaxPost('?wicket:interface=:1:gettingStartedPanel:step_1:zipcode::IBehaviorListener:0:',
>  wicketSerialize(Wicket.$('zip')),function() { }.bind(this),function() { 
> }.bind(this), function() {return Wicket.$('zip') != null;}.bind(this));}">
>
> Should I look at submitting the entire form via Ajax when my conditions are 
> met? Or any other ideas about how to add a form field to the callback?
>
> Here is what I added to my WebPage:
>
>        // Street 1
>        final TextField<String> street1 = new TextField<String>( "street1" );
>        street1.setOutputMarkupId( true );
>        street1.setMarkupId( "address1" );
>        form.add( street1.setRequired( true ) );
>
>        final TextField<String> zipcodeField = new TextField<String>( 
> "zipcode" );
>        zipcodeField.setOutputMarkupId( true );
>        zipcodeField.setMarkupId( "zip" );
>        form.add( zipcodeField.setRequired( true ) );
>
>        zipcodeField.add( new AjaxFormComponentUpdatingBehavior( "onChange" ) {
>            private static final long serialVersionUID = 1L;
>
>           �...@override
>            public void onUpdate( AjaxRequestTarget target ) {
>                System.out.println( "Street 1 (final): " + street1.getValue() 
> );
>                TextField<String> street1f = ( TextField<String> )form.get( 
> "street1" );
>                System.out.println( "Street 1 (form): " + street1f.getValue() 
> );
>                System.out.println( "Zipcode value (form component): " + 
> getFormComponent().getModelObject() );
>            }
>
>           �...@override
>            protected IAjaxCallDecorator getAjaxCallDecorator()
>            {
>                return new AjaxCallDecorator()
>                {
>                    private static final long serialVersionUID = 1L;
>
>                   �...@override
>                    public CharSequence decorateScript( CharSequence script )
>                    {
>                        // Only return the script (which means that it will be 
> executed) after the
>                        // user enters the 5th digit (or more)
>                        return "if(this.value.length >= 5){" + script + "}";
>                    }
>                };
>            }
>        });
>
>
> ...and on another note, I had the same code with an OnChangeAjaxBehavior and 
> the callback was made when the 5th character was typed, but with the 
> AjaxFormComponentUpdatingBehavior the callback was made when the component 
> lost focus ..
>
> Thanks
> Steve
>
>
>
>
> ----- Original Message ----
> From: Igor Vaynberg <igor.vaynb...@gmail.com>
> To: users@wicket.apache.org; Steven Haines <lyg...@yahoo.com>
> Sent: Tue, April 20, 2010 6:25:03 PM
> Subject: Re: OnChangeAjaxBehavior and other form components
>
> user AjaxFormComponentUpdatingBehavior
>
> -igor
>
> On Tue, Apr 20, 2010 at 2:37 PM, Steven Haines <lyg...@yahoo.com> wrote:
>> Hi,
>>
>> I have a form component to which I added an OnChangeAjaxBehavior derivative 
>> and in its onUpdate() method I want to access the contents of it *and* 
>> another form field.
>>
>> Here's what I'm doing:
>>
>>        form.add( new TextField<String>( "street1" ).setRequired( true ) );
>>        final TextField<String> zipcodeField = new TextField<String>( 
>> "zipcode" );
>>        zipcodeField.setOutputMarkupId( true );
>>        zipcodeField.setMarkupId( "zip" );
>>        form.add( zipcodeField.setRequired( true ) );
>>
>>        // Load cities when the zipcode is updated
>>        zipcodeField.add( new OnChangeAjaxBehavior()
>>        {
>>            private static final long serialVersionUID = 1L;
>>
>>           �...@override
>>            protected void onUpdate( AjaxRequestTarget target )
>>            {
>>                //TextField<String> street1 = ( TextField<String> )form.get( 
>> "street1" );
>>                //System.out.println( "Street 1: " + street1.getValue() );
>>                System.out.println( "Zipcode value (form component): " + 
>> getFormComponent().getModelObject() );
>>                // Do something with street1 and the zipcode....
>>            }
>>        } );
>>
>> The problem is that, although I've tried different techniques to obtain the 
>> value of the street1 text field, it is always returning null. I've tried 
>> creating street1 as a final text field and then calling its getValue() 
>> method, I've tried getting it from the form, as above, and I've tried 
>> reading from the underlying form model, all of which return null.
>>
>> Any suggestions?
>>
>> Thanks
>> Steve
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

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

Reply via email to