0

ZK Combobox autoComplete case insensitive

asked 2013-11-05 13:06:33 +0800

javiut gravatar image javiut flag of Venezuela, Bolivarian Republic of
90 1 5

updated 2013-11-27 01:17:49 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

hello i have combobox with autodrop but the autocomplete is doing in case sensitive style i would like be in case insensitive what i am doing wrong there is a workaround thanks a lot.

my code

<combobox id="tc04" autodrop="true" mold="rounded" disabled="true" readonly="true"    width="120px" onSelect='handleOnSelect(self);' onCreate='loadAutocompletableComboBox(self,C01);'  onAfterRender='onAfterRenderCombobox(self);' buttonVisible="false"/>
delete flag offensive retag edit

4 Answers

Sort by ยป oldest newest most voted
0

answered 2013-11-26 03:25:32 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi

You need to implement your sub model

Comparator comparator = new Comparator() {
    public int compare(Object text, Object item) {
        String val = text.toString();
        String itemText = item.toString();
        return itemText.toLowerCase().startsWith(val.toLowerCase()) ? 0 : 1;
    }
};
ListModels.toListSubModel(new ListModelList(list), comparator, 20);
link publish delete flag offensive edit
0

answered 2013-11-26 18:49:44 +0800

javiut gravatar image javiut flag of Venezuela, Bolivarian Republic of
90 1 5

hi jimmyshiau could you post a little more code i mean which class i need to implement this? something like this

public class MyModel extends ListModel implements Comparator<MyModel>

or something thanks a lot..

link publish delete flag offensive edit

Comments

Hi, did you use ListModelList in your combobox?

jimmyshiau ( 2013-11-27 01:18:13 +0800 )edit
0

answered 2013-11-27 15:38:49 +0800

javiut gravatar image javiut flag of Venezuela, Bolivarian Republic of
90 1 5

i am using a simple sample by ZK like this

final ArrayList<String>list = ......
ListModel dictModel= new SimpleListModel(list);
combo.setModel(dictModel);
link publish delete flag offensive edit
0

answered 2013-11-27 17:17:22 +0800

javiut gravatar image javiut flag of Venezuela, Bolivarian Republic of
90 1 5

i have solved using this by another post.

OK, more or less I found a solution to this. Since overwriting SimpleListModel.getSubModel() you can control how the matching is done, it's possible to do a non case-sensitive matching, preventing the user from pressing shift key. Something like this should work, use this SimpleListModelExt class to create a ListModel and feed your combobox.

public class SimpleListModelExt extends SimpleListModel {

    public SimpleListModelExt(List data) {
        super(data);
    }

public ListModel getSubModel(Object value, int nRows) {
        final String idx = value == null ? "" : objectToString(value);
        if (nRows < 0)
            nRows = 10;
        final LinkedList data = new LinkedList();
        for (int i = 0; i < getSize(); i++) {
            if (idx.equals("")
                    || entryMatchesText(getElementAt(i).toString(), idx)) {
                data.add(getElementAt(i));
                if (--nRows <= 0)
                    break; // done
            }
        }
        return new SimpleListModelExt(data);
    }

@Override
    public boolean entryMatchesText(String entry, String text) {
        return entry.toLowerCase().startsWith(text.toLowerCase());
    }

}

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-11-05 13:06:33 +0800

Seen: 53 times

Last updated: Nov 27 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More