textfield

hi

I have two text field and my req is…
if one text field is empty then only another textfield should get enable
and if we typed something it should get disabled…

pls help me out

First: Next time please use more descriptive names for your threads then just textfield.
Second: I don’t know if I understood correctly what you are trying to accomplish.
What i understand was:
There are 2 textfields txt_a and txt_b
At first both textfields are enabled.
If someone changes the value of txt_a and the result is not empty txt_b gets disabled.
If that’s correct you might be able to do it like:

txt_a.addValueChangeListener(new Property.ValueChangeListener(){
   public void valueChange(ValueChangeEvent event){
     if(txt_a.getValue().isEmpty()==false)){
       txt_b.setEnabled(false);
     }
   }
});

That code wasn’t made with an IDE so there are probably some syntax errors.
Also the if statement only gets run if the user presses enter or changes the focus when inside the textfield. If you want to react to a Text change almost immediately you could use TextChangeListener

hi Marius

what u told is correct. this scenario i got , but if m deleting the text from txt_a then txt_b should get enabled.

in a bove code i used else part in that i wrote txt_b.setEnable(true);
but its not getting enabled after deleting the text.

Hm weird.
I just tested it like this:

final TextField txt_a = new TextField("adsfasdf"); layout.addComponent(txt_a); final TextField txt_b = new TextField("adsfasdf"); layout.addComponent(txt_b); txt_a.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { if(!txt_a.getValue().isEmpty()) txt_b.setEnabled(false); else txt_b.setEnabled(true); } }); and it seems to work like a charm. Remember that you need to press Enter or Tab after you remove the content of txt_a.
If you don’t want that you can use TextChangeListener.