1

My problem is, that i want to clear the value of my DatetextField html input whenever my user uncheck a checkbox. I have an AjaxCheckBox and currently just have my condition checking if the value equals false.

@Override
protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
    if(!this.getModelObject()){
       ???
    }
}

Thank you :)

CocoAll
  • 13
  • 4

1 Answers1

4

just set the modelValue of your DatetextField and updated via ajax:

datetextField.setModelObject​(null);
ajaxRequestTarget.add(datetextField);

Don't forget to set a markup id for the datetextField:

datetextField.setOutputMarkupId​(true);
Andrea Del Bene
  • 2,521
  • 1
  • 15
  • 20
  • 1
    Since DatetextField require a Date object, I put ```null``` instead of ```""``` and it workd. I was lacking the ```ajaxRequestTarget.add(datetextField);``` – CocoAll Jul 27 '20 at 08:23
  • @cocoall I've edited my answer to use null. Thanks. – Andrea Del Bene Jul 27 '20 at 08:38
  • In my experience with wicket simply setting the model object to null to clear a form component often doesn't work because wicket still has some value saved in the input or converted input that has not yet been written to the model. So when clearing a FormComponent I always make sure to also call the `clearInput()` method of said component as well. So I'd personally recommend adding `datetextField.clearInput();` just to be on the safe side. – OH GOD SPIDERS Aug 21 '20 at 12:00