hudi
hudi

Reputation: 16555

Disable input text in wicket

I have hml form with two input text

<input type="text" wicket:id = "query"/> 
<input type="text" wicket:id= "address"/>

I need to implement choose mechanism. When someone start to write query then address should be disable and vice versa.

Upvotes: 2

Views: 7725

Answers (3)

magomi
magomi

Reputation: 6685

Add an behavior to the query textfields that listens to onChange event. In the onEvent method disable the address textfield and add it to the ajax request target.

See this example how to add the behavior and how to disable the other component. Keep in mind that you might add some checks if the other component has to be enabled or disabled.

queryTextField.add(new AjaxEventBehavior("onKeyUp") {
        @Override
        protected void onEvent(AjaxRequestTarget target) {
            addressTextField.setEnabled(false);
            target.add(addressTextField);        
        }
    }
);

Upvotes: 6

nobeh
nobeh

Reputation: 10049

You can use:

myTextField.add(AttributeModifier.replace("readonly", "readonly"));

Of course, "readonly" should be determined based on some criteria on your code.

Upvotes: 4

Rens Verhage
Rens Verhage

Reputation: 5857

I would add a behavior to both fields that disables/enables the other field when onKeyUp event is triggered through JavaScript.

Upvotes: 1

Related Questions