Reputation: 199
while renaming a node in jstree, I wanted to validate for special characters in renaming, and if found , I wanted to alert user, and roll back to the old name.
for that I have added
Any help is appreciated.
Upvotes: 2
Views: 3550
Reputation: 199
Instead of binding rename_node
, I needed to bind to rename.jstree
, and then needed to use rollback of action.
Here the bind event code.
if(type === 'rename')
{
var new_Name = data.rslt.new_name;
var iChars = "!@#$%^&*()+=[]\\\';,/{}.-_|\":<>?";
for (var i = 0; i < new_Name.length; i++)
{
if (iChars.indexOf(new_Name.charAt(i)) != -1)
{
alert ("Special characters are not allowed.");
$.jstree.rollback(data.rlbk);
}
}
}
Upvotes: 3
Reputation: 121
You can also do it through rename_node
. If validation fails call:
$('#yourtreeid').jstree("refresh");
Upvotes: 0