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

Caption duplicating label when changing icon sclass

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 8.5.2
    • 8.5.1
    • Components
    • Security Level: Jean
    • None
    • ZK 8.5.2 S1
    • None

      Steps to Reproduce

      	<groupbox>
      		<caption id="cap1" iconSclass="z-icon-plus" label="Testlabel1"/>
      		<button onClick='cap1.setIconSclass("z-icon-globe");'/>
      	</groupbox>
      	<window>
      		<caption id="cap2" iconSclass="z-icon-plus" label="Testlabel2"/>
      		<button onClick='cap2.setIconSclass("z-icon-globe");cap3.setLabel("asdf");'/>
      	</window>
      	<window>
      		<caption id="cap3" iconSclass="z-icon-plus" label="Testlabel3">
      			Some content in caption
      			<button label="some widget in caption"/>
      		</caption>
      		<button onClick='cap3.setIconSclass("z-icon-globe");'/>
      	</window>
      

      clicking either button on the page

      Current Result

      the caption label is duplicated

      Expected Result

      keep the caption (no duplication)

      Root Cause

      the filter condition for counting and removing nodes don't match
      https://github.com/zkoss/zk/blob/v8.5.1/zul/src/archive/web/js/zul/wgt/Caption.js#L51-L61

      consider simplifying the code
      e.g.: the workaround simplifies the removing DOM elements before the first widget's child node without using jquery filter code

      Debug info

      the 3rd case has iconsclass/label + additional child widgets

      Workaround

      Applying this script to affected pages or globally

      <script><![CDATA[
      /*Patch for ZK-3909*/
      zk.afterLoad('zul.wgt', function() {
      	var xCaption = {};
      	zk.override(zul.wgt.Caption.prototype, xCaption, {
      		updateDomContent_ : function() {
      			var cnt = this.domContent_(),
      			dn = this.$n('cave');
      			if (dn) {
      				var firstWgtDom;
      				if (this.firstChild) {
      					firstWgtDom = this.firstChild.$n();
      				}
      				for (var child = dn.firstChild, nextChild; child && child !== firstWgtDom; child = nextChild) {
      					nextChild = child.nextSibling;
      					dn.removeChild(child);
      				}
      				this.clearCache(); //B70-ZK-2370: clearCache after remove dom content
      				jq(dn).prepend(cnt ? cnt : '&nbsp;');
      			}
      		}
      	});//zk.override
      });//zk.afterLoad
      ]]></script>

            klyvechen klyvechen
            cor3000 cor3000
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 1 day
                1d
                Remaining:
                Remaining Estimate - 1 day
                1d
                Logged:
                Time Spent - Not Specified
                Not Specified