Text Field Text Change Listener - Validation

Hi everybody,

can somebody help me?

I´ve got a TextField for a “http;//…” address

now i want to check aftere every letter, if the user adds a correct address starting with the string:“http://”

my plan was to build a “TextChangeListener” to the TxtField and check evey Change the validation

heres my code:


Validator httpValidator = new RegexpValidator("http://",true, "ior address must begin with http://");	
		txt_iorAddress.addValidator(httpValidator);
		txt_iorAddress.isImmediate();
		

		txt_iorAddress.addListener(new TextChangeListener() {
			
			public void textChange(TextChangeEvent event) {
				
				if(event.getSource() == txt_iorAddress){ //Änderung in TextFeld txt_iorAddress
					System.out.println("textchange");
					System.out.println(txt_iorAddress.isValid());
				}
				
			}
			
			
		});

but it don´t work as expected :frowning:

can there be a problem with the missing commit() command?
because when i refresh my browser it works…

sorry for my bad english :slight_smile:

TextChangeEvent contains the current text value in client-side, but the value is not yet updated to the Field i.e. validators are run only when the value is accepted in the client-side. You could try CSValidation add-on from directory it does immediate validation after every key press. Remember to put server-side validators also.
http://vaadin.com/addon/csvalidation