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

button disabled state not synchronized

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: Normal Normal
    • None
    • 6.0.2, 6.5.0
    • Components, Databind 2
    • Windows/Linux, JDK 6, Explorer/Chrome/Firefox

      In the following test case when clicking "Open Editor" the modal window should have an enabled "Save" button but sometimes it is not.
      If the button is enabled the first time the window is opened, then it will always be right.
      If it it not enabled then you have to delete the text (which disables the button) and then retype the text.

      Exchanged JSON messages seem to be right.
      Strangely, without binding the title of the window seems to solve the problem.

      TestVM.java
      public class TestVM {
      	private boolean updating;
      	private boolean editorEnabled;
      	private String text;
      
      	@Command
      	@NotifyChange("editorEnabled")
      	public void doBeforeClose(
      			@ContextParam(ContextType.TRIGGER_EVENT) Event event) {
      		event.stopPropagation();
      		editorEnabled = false;
      		text = null;
      	}
      
      	@Command
      	@NotifyChange({ "editorEnabled", "text", "updating" })
      	public void doEdit() {
      		editorEnabled = true;
      		text = "automatic text";
      		updating = new Random().nextBoolean();
      	}
      
      	@Command
      	@NotifyChange("editorEnabled")
      	public void doSave() throws Exception {
      		// persist text or throw exception
      		editorEnabled = false;
      		text = null;
      	}
      
      	public String getText() {
      		return text;
      	}
      
      	@Init
      	public void init() {
      		editorEnabled = false;
      		text = null;
      	}
      
      	public boolean isEditorEnabled() {
      		return editorEnabled;
      	}
      
      	@DependsOn("text")
      	public boolean isSaveDisabled() {
      		return text == null || text.trim().isEmpty();
      	}
      
      	public boolean isUpdating() {
      		return updating;
      	}
      
      	public void setText(String text) {
      		this.text = text;
      	}
      }
      
      test.zul
      {code:xml}
      <window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('test.TestVM')">
      	<button label="Open Editor" onClick="@command('doEdit')" />
      	<window title="@load(vm.updating ? 'Update' : 'Insert')"
      		mode="modal" width="30em" height="30ex"
      		visible="@load(vm.editorEnabled)" closable="true"
      		onClose="@command('doBeforeClose')">
      		<vlayout vflex="1">
      			<textbox instant="true" rows="2" hflex="1" vflex="1"
      				value="@bind(vm.text)" />
      		</vlayout>
      		<hbox pack="end" width="100%">
      			<button label="Save"
      				onClick="@command('doSave')" disabled="@load(vm.saveDisabled)" />
      		</hbox>
      	</window>
      </window>
      

            Unassigned Unassigned
            benedetti benedetti
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: