-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
}
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.
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;
}
Asked: 2015-03-03 06:52:49 +0800
Seen: 127 times
Last updated: Mar 03 '15
Why are you clearing tempList ? Remove that line and test again
Senthilchettyin ( 2015-03-03 07:35:34 +0800 )editHi, 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 )editDear 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 )edittry to use the listmodel in stead of returning a list, you save a lot of resources.
chillworld ( 2015-03-04 08:00:22 +0800 )editmany thanks for your advice!!!! I'll keep this in mind :)
wangzeyou ( 2015-03-04 10:20:35 +0800 )edit