-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Cannot discern if user cancels edit for nodes #1160
Comments
Hi, The I guess you are trying to persist newly created nodes when the jsTree depends on a completely different concept (like a file system):
So for a list of possible solutions (I do not know if my guesses about what you are trying to achieve are correct):
If the above solutions are not useful to you, please tell me what you are trying to achieve and share any ideas you may have about a solution that I can add to jsTree. I will implement it if it is useful and does not duplicate existing functionality. I am closing this until further information. Best regards, |
Hi thanks for the prompt reply. Let me try to clarify. The workflow I am trying to capture is this:
I don't wish to persist the node until the user confirms their action via the enter key. Even if I wanted to in this particular case I can't because the node name must be unique so the operation may not even succeed. JsTree provides nearly all the functionality required to do this, but just not quite. The callback from the edit function does not include an indication of whether or not the edit was canceled. I don't see where the edit callback contains information about whether or not the action is canceled. Looking at the code I see the edit callback being passed the relevant node and a boolean that indicates whether or not the rename succeeded. But even if the user cancels the action the rename has 'succeeded'. The only time the rename fails is if the operation is not allowed on the tree. In the
but
which is not related to the user's actions. The rename event includes both the old text and new text. In many cases you can simply do:
But that does not allow for the nuance of being allowed to persist a node with the defaultText or cancel the creation of the node if the user has canceled their action. To help illustrate the problem here is a workaround I've developed that I would really prefer to not have to use:
If the user canceled the action both values in the callback will be empty strings, if they confirmed without typing the new value will be "New Node". Using this information I can now persist the created node only when the user has not hit escape to cancel the action. I'd really prefer to not use my workaround if possible. Ideally I would think this sort of information would be communicated by the arguments passed to the edit callback. |
I understand what you need now - thank you, and sorry had to make you clarify. I will add this to the Best regards, |
The edit function for a node to rename a node has support for a user to cancel their edit. When this happens the old value of the node is restored and the input is then blurred.
This works great when a user is editing an existing node, the rename_node event fires and the old and new values of the name are the same so that information can be used to indicate a canceled action. Typically in this case there is no further action that needs to be taken.
However, there are cases where you want the default text to be a valid input that triggers an action (like persisting the node to the server). In those cases it's impossible to tell if the user canceled the edit with escape or committed the default value using enter.
All the necessary information is tracked, but neither the edit callback nor the rename_node event are privy to this information. As far as I can tell there's no way to discern that information cleanly outside of jsTree.
The text was updated successfully, but these errors were encountered: