我有一个项目列表,上面有一个输入字段。
输入字段是一个过滤器,它应该根据输入字段输入的文本过滤列表。
例如:如果键入"th",它应该筛选列表,以便所有项目都以"th“开头。
为此,我使用AjaxFormComponentUpadingBehavior("onkeypress").
但这似乎是行不通的--他们应该这样做。
当我输入某项内容时,它会清除它,并将光标移到输入字段的第一个字母。
我试过onkeyup和onkeydown,它们的行为都是一样的。
现在,我正在做一个链接点击过滤器的工作,但我希望它是无缝的按钮。
有办法做到这一点吗?我使用的是wicket 1.4.x
以下是代码:
// Customer Filter input field
customerFilterTxt = new TextField<String>("customerFilterTxt", new PropertyModel<String>(this, "slectedCustomerFilterStr"));
customerFilterTxt.setOutputMarkupPlaceholderTag(true);
customerListViewContainer.add(customerFilterTxt);
// Ajax behavior for customer group filter auto complete input filed
AjaxFormComponentUpdatingBehavior customerGroupFilterBehave = new AjaxFormComponentUpdatingBehavior("onkeypress") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
List<CustomerGroupBean> filterList = new ArrayList<CustomerGroupBean>();
if(Util.hasValue(selectedCustomerGroupFilterStr)) {
String str = selectedCustomerGroupFilterStr.toUpperCase();
for(CustomerGroupBean group : custGroupList) {
if(group.getRightGroupName().toUpperCase().contains(str)) {
filterList.add(group);
}
}
custGroupListView.setList(filterList);
} else {
custGroupListView.setList(custGroupList);
}
target.addComponent(customerFilterTxt);
target.addComponent(custGroupListViewContainer);
}
};
customerGroupFilterTxt.add(customerGroupFilterBehave);发布于 2015-05-06 07:33:35
在update方法中将输入字段添加到更新调用中。这指示Wicket替换输入字段,再次呈现文本字段。这就是为什么光标跳到第一个位置的原因。为什么要将文本字段添加到更新中?我看不出有什么必要。此外,您可能希望使用事件"onkeyup"。
https://stackoverflow.com/questions/30069734
复制相似问题