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

Listbox in select mold setModel + set selectedIndex causes unsync selection state

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • None
    • 9.6.0.1
    • None
    • None

      Steps to Reproduce

      Run fiddle

      https://zkfiddle.org/sample/25i2bpb/3-listbox-select-event

      Click on the button

      Open select, choose Item 2

      Open select, choose Item 1

      Current Result

      Only the first onSelect event after clicking button is triggered, other selections after that fail to trigger

      Expected Result

      selection should work

      Debug Information

      Caused by desync between listbox._selectedIndex and individual listitem.isSelected() at client-side.

      {"rs":[["rm",["o9lS9"]],["rm",["o9lS4"]],["addChd",["o9lS2",[ //REMOVING THE OLD LISTITEMS, this should clear selectedIndex from listbox, but since the items are no longer bound, it fails to do so.
      ['zul.sel.Option','o9lS5',{selected:true,_loaded:true,_index:0},{},[ //Created with selected state
      ['zul.sel.Listcell','o9lS6',{label:'item 1'},{},[]]],'select']],[
      ['zul.sel.Option','o9lS3',{_loaded:true,_index:1},{},[
      ['zul.sel.Listcell','o9lSa',{label:'item 2'},{},[]]],'select']]]],["setAttrs",[{$u:'o9lS2'},["_lastoffset",0,"resetDataLoader",true,"$onDataLoading",true,"$onTopPad",false,"visibleItemCount",2,"selectedIndex",0]]]],"rid":5}
      

      When selecting item2 after triggering the model / selection replacement, item2 becomes selected, but item1 doesn't become unselected, because the listbox.clearSelection() tries to unselect the previous listitem widget (from listbox._selItems), instead of unselecting the currently selected item.

      Workaround

      listbox.invalidate(); after setting model / selection

            DevChu DevChu
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: