I'm in wicket 6. I've got an autocomplete field that I want to capture when someone completes the field, either by fully typing a finished ID, or by selecting one from the list and moving on from the field.
AutoCompleteTextField<AssetInfo> assetID = new AutoCompleteTextField<AssetInfo>("assetId", Model.of(new AssetInfo()), AssetInfo.class, renderer, assetInfoSettings) {
private static final long serialVersionUID = 1L;
@Override
protected Iterator<AssetInfo> getChoices(String input) {
return assetInfoService.fetchAssetIDsForComplete(input).iterator();
}
};
assetID.add(new AjaxFormSubmitBehavior("onselect") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target) {
onAssetIdSelect(target);
}
});
assetID.add(new AjaxFormSubmitBehavior("onchange") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target) {
onAssetIdSelect(target);
}
});
I tried both AjaxFormSubmitBehavior and AjaxFormComponentUpdatingBehavior. Neither is firing the event to me. I looked in the network tab of the browser, and I can see the select of something from the list creates an ajax event, but not the field exit after typing. And neither gets to my behavior code.
It appears that wicket 7 has a onSelect method on the autocomplete itself, but not wicket 6.x, which I'm in and don't currently have permission to move on from. I presume the reason is that the onchange of the textbox is probably bound to some internal ajax behavior designed to create the list...so how can I trap the event I need to control the render of the rest of the page? I could create an extra button for the user to signal their completion, but the users have expressed preferring the finishing of typing itself to trigger this action.
Wicket examples shows this exact usage:
https://github.com/apache/wicket/blob/6ad2f9834e02030a2d5b47ee215276b9be7e5623/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AutoCompletePage.java#L117