Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid gets stuck with inEditMode flag set #2024

Open
ECrosland opened this issue May 27, 2021 · 3 comments
Open

Grid gets stuck with inEditMode flag set #2024

ECrosland opened this issue May 27, 2021 · 3 comments
Labels
Bug This needs fixing Debatable

Comments

@ECrosland
Copy link

Short description
I noticed that my grid would enter a state where double clicking an editable cell would no longer enter into editing mode on that cell. Such edits had been working just moments earlier in the same browser window.

Steps to reproduce or sample
This situation comes about when I try to arrange for edits to a cell to be submitted immediately back to the server. I do this by placing a call to the grid's save method within an event handler for the grid's change event.

It seems that what happens is that the save request is sent to the server, and then the selection moves to the next cell in the column. So far so good.

When the save request completes, the grid then refreshes itself. As part of this, a refreshBody method is called, which replaces the HTML for the grid body, and we thereby lose the input element that had been present for editing. However, although this element goes away, grid.last.inEditMode remains set to true. When, therefore, editField is called again in response to a double click, after checking this flag, it appears to the implementation as though editing is already underway, and it does not create a new input element for editing whichever cell was just double clicked.

This, at least, is what my time spent with the debugger seemed to reveal to me.

It seems to me there's a bug here, although I know it's also possible I'm misusing the API in some way.

As a side note, I'd be happy to keep the edit cursor from automatically advancing to the next cell in the column, since that doesn't really suit my use case anyway. That should have the happy side effect of keeping this problem from manifesting for me.

@ECrosland
Copy link
Author

I was wondering why I didn't end up in this situation if I invoked save in response to a button click.

It seems that the blur handler on line 2956 in w2grid.js (and in comparable places on other switch branches) is ordinarily used to remove the input element and reset the internal state, including the inEditMode flag. However, this handler isn't invoked when the body HTML is replaced, as it is in the sequence of events described above.

w2ui/src/w2grid.js

Lines 2956 to 2959 in 4d98cee

$(tmp).on('blur', function(event) {
if ($(this).data('keep-open') == true) return
obj.editChange.call(obj, input, index, column, event)
})

@vitmalina
Copy link
Owner

If PR mentioned here resolve provide a solution, please close this issue.

@ECrosland
Copy link
Author

The PR that adds editAutoAdvance allows me to avoid ending up in the situation where the identified problem manifests, and this is fine in my use case, since I would prefer not to have the auto-advance behavior anyway.

However, this doesn't address the problem itself, I don't think. That is, if I have a call to the grid's save method in a change event handler, and editAutoAdvance has not been disabled, then the grid ends up in a state where no further inline edits can be made until the page is refreshed, for reasons I tried to outline above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This needs fixing Debatable
Projects
None yet
Development

No branches or pull requests

3 participants