vaadin/flow-components

Grid Editor does not reset binder when calling cancel method

Opened this issue · 0 comments

Description

If you have an editable grid, and you trust in binder to check whether the editor is dirty, you can not trust in the bender. hasChanges() because it remains true after calling editor.cancel()

Expected outcome

bender. hasChanges() returns false after calling editor.cancel()

Minimal reproducible example

    	// Set the binder
    	editor.setBinder(binder);
    	
    	// edit the item
    	editor.editItem(person); 

    	System.err.println("Before Modify: " + binder.hasChanges());
    	// HERE the user modifies some fields
    	
        System.err.println("After Modify and Before Cancel: " + binder.hasChanges());
    	editor.cancel();
        editor.closeEditor();
        System.err.println("After Cancel: " + binder.hasChanges());

It prints

Before Modify: false
After Modify and Before Cancel:  true
After Cancel:  true

instead of

Before Modify: false
After Modify and Before Cancel:  true
After Cancel:  false

Workaround

       editor.cancel();
        // workaround because cancel should clear binder
        binder.refreshFields();
        editor.closeEditor();

Steps to reproduce

  • Download a project from start.vaadin.com with a view that adds SamplePerson e.g. master-detail
  • Add this view to the project (adjust packages)
    GridEditView.java.zip
  • Run the project and open /grid-edit
  • Edit a row, modify any field and push cancel button
  • Discard changes
  • Try to edit another row, you cannot

Environment

Vaadin version(s): 24.4.x

Browsers

No response