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

zhtml inconsistent "checked" property

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 8.0.3
    • 8.0.2
    • ZHTML
    • Security Level: Jimmy
    • ZK 8.0.3 S8

      steps to reproduce

      run the attached example, and observe the initial and dynamic updates

      actual result

      using checked="false" initially or calling setChecked(false) during the initial rendering causes the checkbox to be checked
      calling setChecked(true/false) dynamically works

      calling setChecked twice causes multiple response commands sent to the client, causing unnecessary network traffic

      using the html conform values such as checked="checked" or not setting the the property at all (calling setDynamicProperty("checked", null/"checked")) works when initially rendering the component, however dynamic changes always result in an unchecked checkbox

      expected result

      consistent behavior, either true/false or "checked"/null.
      This inconsistency requires additional customization when integrating the input element with ZKBind.

      To avoid duplicate setAttr commands a mechanism like smartUpdate should be considered

      Workaround

      a custom component class to get things working from the server side:

      @ComponentAnnotation("checked:@ZKBIND(ACCESS=both, SAVE_EVENT=onCheck)")
      public class CheckableInput extends Input {
      	private static final long serialVersionUID = 1L;
      	
      	@Override
      	public boolean isChecked() {
      		return getDynamicProperty("checked") != null;
      	}
      	
      	@Override
      	public void setChecked(boolean checked) {
      		setDynamicProperty("checked", checked ? true : null);
      	}
      }
      

      this results in the DOM attribute checked="true" being rendered.
      However this should rather be checked="" or checked="checked"
      (refer to https://www.w3.org/TR/html-markup/input.checkbox.html#input.checkbox.attrs.checked)

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

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour
                1h