1

How to clear display value when clear combox's items

asked 2015-03-03 06:52:49 +0800

wangzeyou gravatar image wangzeyou
12 2

updated 2015-03-03 06:53:48 +0800

Hi, I'm using ZK 7.0.3 MVVM and after I clear the combobox's items, sure that there's no comboitem under the combobox, but the value still displayed on the combobox.

How can I clear the display value in the combobox?
Do I have to wire the ComboBox on the zul to clear the display value?

    <row>
    <combobox model="@bind(vm.tempList)" 
            selectedItem="@bind(vm.selectedItem)" readonly="true">
        <template name="model" var="each">
            <comboitem label="@load(each)"/>
        </template>
    </combobox>
</row>
<row>
    <button label="clear" onClick="@command('clear')"/>
</row>



    //IN THE ViewModel:
     List<String> tempList = new ArrayList<String>(Arrays.asList("1", "2", "3", "4", "5"));
   String selectedItem = tempList.get(0);
        // getters and setters

    @Command
    @NotifyChange({"tempList", "selectedItem"})
    public void clear()
    {
        tempList.clear();
        selectedItem = null;     // <---   clear selection, but still displayed on combobox
    }
delete flag offensive retag edit

Comments

Why are you clearing tempList ? Remove that line and test again

Senthilchettyin ( 2015-03-03 07:35:34 +0800 )edit

Hi, I clear the tempList because I'll load the data into combobox dynamiclally, and when there's no data, I clear the combobox, and set selectedItem to none, and when I do that, display value is still there......

wangzeyou ( 2015-03-04 06:30:26 +0800 )edit

Dear All, I found that both using List and using ListModelList work, There must be something wrong with my project, and I'll try out to find i out thanks for all your help!

wangzeyou ( 2015-03-04 07:27:02 +0800 )edit

try to use the listmodel in stead of returning a list, you save a lot of resources.

chillworld ( 2015-03-04 08:00:22 +0800 )edit

many thanks for your advice!!!! I'll keep this in mind :)

wangzeyou ( 2015-03-04 10:20:35 +0800 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2015-03-03 07:40:39 +0800

chillworld gravatar image chillworld flag of Belgium
5367 4 9
https://github.com/chillw...

Actually, try using ListModel in stead of List.

Don't forget if you return a List => There is always behind the back a creation of a new ListModelList.

I created a fiddle with your code and also updated it to usage of ListModel and it works like that.

Greetz chill.

link publish delete flag offensive edit

Comments

thanks it worked :D

kleponboy ( 2015-11-09 06:01:39 +0800 )edit
1

answered 2015-03-03 07:44:56 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Here is example from my current project. I use delete key to delete the value

<combobox
                                            model="@load(vm.appointmentTypesList)" hflex="1"
                                            ctrlKeys="#del"
                                            onCtrlKey="@command('onClearType')"
                                              readonly="true"
                                            selectedItem="@bind(vm.selectedApptType)"
                                            mold="rounded" cols="30"  >
                                            <template name="model"
                                                var="p">
                                                <comboitem
                                                    label="@load(p.typeName)" />
                                            </template>
                                        </combobox>

@NotifyChange({ "selectedApptType" })
    @Command
    public void onClearType() {
        this.selectedApptType = null;
    }
link publish delete flag offensive edit

Comments

This code helps me on ZK project development, thank you for taking time to reply to my problem. :)

wangzeyou ( 2015-03-04 10:28:46 +0800 )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
2 followers

RSS

Stats

Asked: 2015-03-03 06:52:49 +0800

Seen: 127 times

Last updated: Mar 03 '15

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