0

I have a component that extends TextField where a user can type an web address. I want that after the user type something (for example www.example.org) to change that value to something else (for exemple http://www.example.org)

I have tried this:

urlField = new TextFieldIndicatingError<String>("url", new PropertyModel<String>(this, "url"));
urlField.add(new AjaxFormComponentUpdatingBehavior("onblur") {
                     @Override
                     protected void onUpdate(AjaxRequestTarget target) 
                     {
                         //url = "ABCDDEE";
                         urlField.getModel().setObject("AAAA");
                     }
                 });

but anything inside the onUpdate() doesn't seems to have an effect in the TextField's value. What I'm doing wrong here?

Alex
  • 2,213
  • 4
  • 32
  • 44
  • On top of martin answer .To update the `urlField` make sure you are having `urlField.setOutputMarkupId(true)` also – soorapadman Nov 23 '17 at 06:11
  • It's not "onblur" but "blur". And it will execute the event when the user will change the focus. To do something when the user type something, you must use the event "keyup". – stefv Aug 27 '20 at 12:14

1 Answers1

0

You need to use target.add(urlField) to update it on the client side after setting its new model.

martin-g
  • 17,243
  • 2
  • 23
  • 35