Hi I have a checkbox which must be checked for the user to be able to submit (accept terms). I want the related submit button to be enabled only, when the checkbox is checked. This works fine when the button initially is disabled, then the checkbox is checked by the user (I followed http://www.nabble.com/Disabling-and-enabling-components-using-AjaxCheckBox-td20911338.html#a20911338). However, when the user then unchecks the checkbox again, the button does not get disabled again :-(
Any suggestions? <div wicket:id="feedback"></div> <form wicket:id="form"> <span wicket:id="border"><input type="checkbox" wicket:id="acceptCB" id="acceptCB" /></span> <label for="acceptCB"><wicket:message key="acceptCB">[Accept delete]</wicket:message></label> <br/> <input type="submit" value="[Confirm]" id="confirmBtn" wicket:id="confirmBtn" wicket:message="value:confirmBtn"/> </form> ========== /** Whether or not the conditions for deletion are accepted. Acts as IModel for the checkbox */ private boolean accepted = false; /** The confirm button */ Button confirmBTN = null; /** The accept check box */ CheckBox acceptCB = null; public AccountDeletePage() { add(new FeedbackPanel("feedback")); Form form = new Form("form"); add(form); confirmBTN = new Button("confirmBtn") { @Override public void onSubmit() { doDelete(); } }; confirmBTN.setEnabled(false); confirmBTN.setOutputMarkupId(true); //not sure why this is needed form.add(confirmBTN); //CheckBox acceptCB = new CheckBox("acceptCB", new PropertyModel(this, "accepted")); acceptCB = new AjaxCheckBox("acceptCB",new PropertyModel(this, "accepted")) { @Override protected void onUpdate(AjaxRequestTarget arg0) { doUpdateConfirmButton(); if(arg0 != null) { arg0.addComponent(confirmBTN); } } }; acceptCB.setRequired(true); form.add(new FormComponentFeedbackBorder("border").add(acceptCB)); } /** * Updates the enabled state of the delete button depending on acceptance */ private final void doUpdateConfirmButton() { boolean enabled = acceptCB.isEnabled(); confirmBTN.setEnabled(enabled); }