You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by lucast <lu...@hotmail.com> on 2011/07/18 12:16:21 UTC

AjaxFormComponentUpdatingBehavior("onchange") not working on DropDownChoice

Dear Forum,
I have added AjaxFormComponentUpdatingBehavior to a DropDownChoice to hide a
text field or to make it visible, according to the value selected from
DropDownChoice.

AjaxFormComponentUpdatingBehavior is hiding the text field, as expected, but
it is not making it visible when it should.
Surely, if it hides a form object, it should equally make it visible, should
it not?
Code:

public class HomePage extends WebPage {
	DropDownChoice<String> choice = new DropDownChoice<String>("choice", new
Model<String>(), Arrays.asList( new String[] { "A", "B", "C" } ));
	TextField<String> textField = new TextField<String>("textField", new
Model<String>());
	Form textDropDownAjaxForm = new Form("genericForm");
	
    public HomePage(final PageParameters parameters) {
    	
    	textDropDownAjaxForm.add(textField);
    	textDropDownAjaxForm.add(choice);
    	add(textDropDownAjaxForm);
    	
	textField.setOutputMarkupId(true);
    	choice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
		protected void onUpdate(AjaxRequestTarget target) {
            		if ( choice.getModelObject() == "A" ){
            			*textField.setVisible(true);*
	            	} else {
        	    		*textField.setVisible(false);*
	            	}
        	        *target.addComponent(textField);*
	       }
        });
    }
}

and here is the HTML:
<body>
        <form wicket:id="genericForm">
            <select wicket:id="choice">
                <option>Choose one</option>
            </select>
            text field: <input wicket:id="textField" type="text" />
        </form>
    </body>

Thanks in advance for any help,
Lucas

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxFormComponentUpdatingBehavior-onchange-not-working-on-DropDownChoice-tp3674937p3674937.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: AjaxFormComponentUpdatingBehavior("onchange") not working on DropDownChoice

Posted by Martin Grigorov <mg...@apache.org>.
textField.setOutputMarkupPlaceholderTag(true);

On Mon, Jul 18, 2011 at 1:16 PM, lucast <lu...@hotmail.com> wrote:
> Dear Forum,
> I have added AjaxFormComponentUpdatingBehavior to a DropDownChoice to hide a
> text field or to make it visible, according to the value selected from
> DropDownChoice.
>
> AjaxFormComponentUpdatingBehavior is hiding the text field, as expected, but
> it is not making it visible when it should.
> Surely, if it hides a form object, it should equally make it visible, should
> it not?
> Code:
>
> public class HomePage extends WebPage {
>        DropDownChoice<String> choice = new DropDownChoice<String>("choice", new
> Model<String>(), Arrays.asList( new String[] { "A", "B", "C" } ));
>        TextField<String> textField = new TextField<String>("textField", new
> Model<String>());
>        Form textDropDownAjaxForm = new Form("genericForm");
>
>    public HomePage(final PageParameters parameters) {
>
>        textDropDownAjaxForm.add(textField);
>        textDropDownAjaxForm.add(choice);
>        add(textDropDownAjaxForm);
>
>        textField.setOutputMarkupId(true);
>        choice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
>                protected void onUpdate(AjaxRequestTarget target) {
>                        if ( choice.getModelObject() == "A" ){
>                                *textField.setVisible(true);*
>                        } else {
>                                *textField.setVisible(false);*
>                        }
>                        *target.addComponent(textField);*
>               }
>        });
>    }
> }
>
> and here is the HTML:
> <body>
>        <form wicket:id="genericForm">
>            <select wicket:id="choice">
>                <option>Choose one</option>
>            </select>
>            text field: <input wicket:id="textField" type="text" />
>        </form>
>    </body>
>
> Thanks in advance for any help,
> Lucas
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxFormComponentUpdatingBehavior-onchange-not-working-on-DropDownChoice-tp3674937p3674937.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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