Reputation: 178
I have a form with 2 date fields and one button. I need to make button that disabled when dates are invalid and enable opposite dynamicly when user types dates in fields. How can I refresh the button in page?
Code below doesn't work. I know I have to do something that refresh elements in page, but I don't know how to do it.
private void initFields() {
startDate = new DateTextField("startDate", "Дата начала периода", null, NSDConsts.DATE_FORMAT);
startDate.setOutputMarkupId(true);
startDate.addSubmitter();
startDate.getFormComponent().add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget paramAjaxRequestTarget) {
startDateValue = startDate.getDate();
exportButtonVisibility();
}
});
form.add(startDate);
endDate = new DateTextField("endDate", "Дата окончания периода", null, NSDConsts.DATE_FORMAT);
endDate.setOutputMarkupId(true);
endDate.addSubmitter();
endDate.getFormComponent().add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget paramAjaxRequestTarget) {
endDateValue = endDate.getDate();
exportButtonVisibility();
}
});
form.add(endDate);
exportButton = new CinimexAjaxLink("createButton", "Создать", new NRDTextLinkDecorator()) {
@Override
public void onClick(AjaxRequestTarget target) {
if (dateTextFieldCheck(startDate, endDate)) {
((ActionsAuditManager) getManagerFacade().getManager(ActionsAuditManager.BEAN_NAME)).createNote(AuditActions.CALCULATE_DETALIZATION, "Отчет успешно сформирован", null, null);
download.initiate(target);
} else {
String message = "Введена неверная дата";
if (startDate.getString().compareTo(endDate.getString()) > 0) {
message = "Дата начала периода не может быть больше даты окончания";
}
getDialogWindow().showInfo(message);
}
}
};
exportButton.add(download);
form.add(exportButton);
}
private void exportButtonVisibility () {
if (dateTextFieldCheck(startDate, endDate)) {
exportButton.setEnabled(true);
} else {
exportButton.setEnabled(false);
}
}
Upvotes: 0
Views: 1067
Reputation: 2341
You need to tell Wicket to update the export after the change in the dates; so modify the update method in both dates field:
@Override
protected void onUpdate(AjaxRequestTarget paramAjaxRequestTarget) {
endDateValue = endDate.getDate();
exportButtonVisibility();
paramAjaxRequestTarget.add(exportButton); // Add this line
}
Upvotes: 3