Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-1891

Combobox with Validator will trigger reload selectedItem when typing

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.5.4
    • Component/s: Databind 2
    • Labels:
      None

      Description

      http://screencast.com/t/vl153iYts5

      <zk>
      	<zscript><![CDATA[
      		class MyVM {
      			private ListModel model;
      			private Item selItem;
      			
      			public MyVM () {
      				List list = new ArrayList();
      				list.add(new Item("01"));
      				list.add(new Item("02"));
      				list.add(new Item("03"));
      				model = ListModels.toListSubModel(
      					new ListModelList(list), new ItemComparator(), 10);
      			}
      			
      			public ListModel getModel () {
      				return model;
      			}
      			
      			public Item getSelItem () {
      				return selItem;
      			}
      			
      			public void setSelItem (Item selItem) {
      				this.selItem = selItem;
      			}
      			
      			public Validator getValidator(){
      			    return new Validator();
      			}
      		}
      		
      		class Item {
      			private String name;
      			public Item (String name) {
      				this.name = name;
      			}
      			public String getName () {
      				return name;
      			}
      		}
      		
      		class ItemComparator implements Comparator {
      			public int compare(Object text, Object item) {
      			    String val = text.toString().toLowerCase();
      
      			    if (val.isEmpty())
      			    	return 0;
      			    String name = "";
      			    if (item instanceof Item) {
      			    	name = ((Item)item).getName();
      			    }
      			    return name.toLowerCase().startsWith(val)? 0: -1;
      			}
      		}
      		
      		class Validator extends org.zkoss.bind.validator.AbstractValidator {
      			 public void validate(ValidationContext ctx) {
      	            if (ctx.getProperty().getValue() == null)
      	            	addInvalidMessage(ctx, "Please select an item!!");
      	        }
      		}
      	]]></zscript>
      	<window apply="org.zkoss.bind.BindComposer" 
      		viewModel="@id('vm') @init('MyVM')"
      		validationMessages = "@id('vmsgs')">
      		<combobox id="cb" model="@load(vm.model)" 
      			selectedItem="@bind(vm.selItem)@validator(vm.validator)"
      			autodrop="true" autocomplete="false">
      			<template name="model">
      				<comboitem label="@load(each.name)"/>
      			</template>
      		</combobox>
      		<label value="@load(vmsgs[cb])" style="color:red;" />
      	</window>
      
      	
      </zk>
      

        Activity

        Hide
        dennis dennis added a comment -

        Steps
        1.select '01', the selItem change to item01
        2.in combobox, delete char '1', and tab out. you will see a warn, and the selItem is still item01
        3.in combobox, delete char '0', wait, you will see the value of combobox become '01' again.

        Cause
        1.select 01, the selItem change to item01
        2.When delete char '1', and tab out. it fires onChange, the validator block the update, so, in combobox the selection is null, but in model it is still item01
        2.1 when delete char '1' onChanging -> onAfterRender, selItem is already in model's selection set, so the combobox string doesn't be reload
        3.When, delete char '0', combobox fires onChanging and this cause combobox fire onAfterRender, and triggers zkbind load selItem to model, and this cause combobox to reload the selected value to '01'

        Show
        dennis dennis added a comment - Steps 1.select '01', the selItem change to item01 2.in combobox, delete char '1', and tab out. you will see a warn, and the selItem is still item01 3.in combobox, delete char '0', wait, you will see the value of combobox become '01' again. Cause 1.select 01, the selItem change to item01 2.When delete char '1', and tab out. it fires onChange, the validator block the update, so, in combobox the selection is null, but in model it is still item01 2.1 when delete char '1' onChanging -> onAfterRender, selItem is already in model's selection set, so the combobox string doesn't be reload 3.When, delete char '0', combobox fires onChanging and this cause combobox fire onAfterRender, and triggers zkbind load selItem to model, and this cause combobox to reload the selected value to '01'
        Hide
        dennis dennis added a comment -

        combobox doesn't have to count on onAfterRender in zk 6, and this unnecessary behavior cause this issue. remove the LOAD_EVENT configuration in zkbind lang-addon.xml fixes this.

        fixed since 2013/8/26

        Show
        dennis dennis added a comment - combobox doesn't have to count on onAfterRender in zk 6, and this unnecessary behavior cause this issue. remove the LOAD_EVENT configuration in zkbind lang-addon.xml fixes this. fixed since 2013/8/26

          People

          • Assignee:
            Unassigned
            Reporter:
            jimmyshiau jimmyshiau
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: