"Clear" button for combobox

asked 2019-02-18 14:29:35 +0800

pavelEW gravatar image pavelEW
53 4

updated 2019-02-20 10:30:53 +0800

cor3000 gravatar image cor3000
6032 2 7
ZK Team

Hi guys :)

I want to add a "clear" button to my comboboxes which will clear the selected value in it and in a form.

It's easy to do this when you know what value will be cleared. But in my case I have few search forms with 3-5 comboboxes there. All values are beaing stored to a search bean - simple POJO.

<div form="@id('fx') @load(vm.orderLookup) @save(vm.orderLookup, before='onSearch')">

I've tried to pass a combobox component to my @Command method and set selected value to null there, but it doesn't affect value in proxy form somehow.

Here is my combobox, it is used as template and on search form I only apply those templates with needed parameters:

<zk xmlns="I'm sorry I can't publish links :(">
<n:div class="form-group">
    <label sclass="control-label ox-field-label-transparent" value="@load(label)"/>
    <combobox selectedItem="@bind(selectedItem)" model="@init(model)">
        <template name="model" var="p">
            <comboitem value="@load(p.uid)" label="@load(p.proxy)"/>
    <n:div class="input-group">
        <n:span class="input-group-btn">
            <h:a class="btn btn-sm btn-default fa fa-times-circle close" type="button" style="border:none"/>

Any ideas on how it could be done?

delete flag offensive retag edit


now you can post links ;)

cor3000 ( 2019-02-20 10:30:28 +0800 )edit

1 Answer

Sort by » oldest newest most voted

answered 2019-02-20 11:08:50 +0800

cor3000 gravatar image cor3000
6032 2 7
ZK Team

updated 2019-02-20 11:09:23 +0800

To change a value in the proxy object you usually just have to call the setter.

BindUtils.postNotifyChange(null, null, formproxy, "gender"); //maybe happens even automatically

However you can call the JS function at client side as if the user deleted the current value himself


This will just trigger the same events and result in the same commands and invoke data bindings as with normal user interaction.

The advantage is, that the server side doesn't need any additional logic, the disadvantage is a slightly ugly JS call, which you can move to a utility script file.

link publish delete flag offensive edit


Thank you for your reply cor3000. I have a few forms with dozen comboboxes there so I didn't want to use that approach with serverside. It would make me to write a huge switch and modify a java code if new combobox is added. model.removeFromSelection() didn't trigger the event, so nothing changed.

pavelEW ( 2019-02-20 13:56:13 +0800 )edit

I also found your approach yesterday. I'm not a big guy in JS, so it took me some time to figure out how it could be done. I did it a little bit more accurate by overriding a Combobox in my JS and adding a function clear. So my JQ call is a little bit nicer than yours. Any way thanks for your reply!

pavelEW ( 2019-02-20 14:06:51 +0800 )edit

yes if this is a reused feature extending the JS widget will perform better. Good to see the ideas match, and you found a cleaner way for your scenario.

cor3000 ( 2019-02-22 10:41:04 +0800 )edit

Btw, cor3000, any ideas why potix guys do not reply on our emails about buying a license?

pavelEW ( 2019-02-22 16:11:56 +0800 )edit

@pavelEW, please check your inbox/spam folder for the response, thanks!

michellechen ( 2019-02-22 17:25:09 +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




Asked: 2019-02-18 14:29:35 +0800

Seen: 9 times

Last updated: Feb 20 '19

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