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

Select all cause exception if no selectable item is rendered yet

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 8.5.1
    • 8.0.4.2
    • ZK Client Engine
    • Security Level: Jimmy
    • None
    • IE11

      Steps to Reproduce

      Run the fiddle:
      http://zkfiddle.org/sample/32u4u8q/3-checkable-wrong-rendering#source-1

      Click the "select all" checkbox
      Scroll down to row 20

      Current Result

      A JS exception is thrown in the console

      zul.sel.wpd:1022 Uncaught TypeError: Cannot read property '$n' of undefined
          at init.fireOnSelect (zul.sel.wpd:1022)
          at init._zkf (zul.sel.wpd:951)
          at init._doClick (zul.sel.wpd:2531)
          at HTMLSpanElement.<anonymous> (zk.wpd:15037)
          at HTMLSpanElement.dispatch (zk.wpd:5157)
          at HTMLSpanElement.elemData.handle (zk.wpd:4828)
      

      Selectable items not yet rendered are not selected

      Expected Result

      no exception
      select all should select items

      Debug Info

      Does not happen with EE ROD (only happen with CE ROD - live data)

      Root Cause

      If no selectable items are currently rendered, this.getSelectedItem() will return a null value in zul.sel.Listbox.selectAll when passing it as ref to fireOnSelect(ref, evt)
      during fireOnSelect, cm = ref.$n('cm') is called to find the checkmark of this non-existent

      Workaround

      	<script><![CDATA[
      		zk.afterLoad('zul.sel', function() {
      			var xListbox = {};
      			zk.override(zul.sel.Listbox.prototype, xListbox ,{
      				selectAll : function (notify, evt) {
      					for (var it = this.getBodyWidgetIterator(), w; (w = it.next());)
      						if (w._loaded && !w.isDisabled() && w.isSelectable())
      							this._changeSelect(w, true);
      					if(!this.getSelectedItem())
      						this._shallSyncCM = false;
      					if (notify && evt !== true && this.getSelectedItem())
      						this.fireOnSelect(this.getSelectedItem(), evt);
      				}
      			});//zk.override
      		});//zk.afterLoad
      	]]></script>
      

            rudyhuang rudyhuang
            CJahn CJahn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 4 hours
                4h
                Remaining:
                Time Spent - 2 hours Remaining Estimate - 2 hours
                2h
                Logged:
                Time Spent - 2 hours Remaining Estimate - 2 hours
                2h