setting.callback.beforeRename.html 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <div class="apiDetail">
  2. <div>
  3. <h2><span>Function(treeId, treeNode, newName, isCancel)</span><span class="path">setting.callback.</span>beforeRename
  4. </h2>
  5. <h3>Overview<span class="h3_info">[ depends on <span
  6. class="highlight_green">jquery.ztree.exedit</span> js ]</span></h3>
  7. <div class="desc">
  8. <p></p>
  9. <div class="longdesc">
  10. <p>Specify callback function to be called before rename(when input DOM blur or press Enter Key), The
  11. return value controls the allow to rename node.</p>
  12. <p class="highlight_red">When node is editing name, press the ESC key to restore the original name and
  13. stop edit name.</p>
  14. <p class="highlight_red">From v3.5.13, zTree will trigger this callback when user cancel edit name.
  15. please see 'isCancel' parameter.</p>
  16. <p>Default: null</p>
  17. </div>
  18. </div>
  19. <h3>Function Parameter Descriptions</h3>
  20. <div class="desc">
  21. <h4><b>treeId</b><span>String</span></h4>
  22. <p>zTree unique identifier: <b class="highlight_red">treeId</b>.</p>
  23. <h4 class="topLine"><b>treeNode</b><span>JSON</span></h4>
  24. <p>JSON data object of the node to be rename.</p>
  25. <h4 class="topLine"><b>newName</b><span>String</span></h4>
  26. <p>the new name</p>
  27. <h4 class="topLine"><b>isCancel</b><span>Boolean</span></h4>
  28. <p>the status about cancel edit name (v3.5.13+)</p>
  29. <p class="highlight_red">isCancel = true means: user cancel edit name. (press ESC or use cancelEditName()
  30. function)</p>
  31. <p class="highlight_red">isCancel = false means: user submit edit name.</p>
  32. <h4 class="topLine"><b>Return </b><span>Boolean</span></h4>
  33. <p>return true or false</p>
  34. <p class="highlight_red">If return false, the treeNode will keep the editing name, don't trigger the
  35. 'onRename' callback, and will ignore other enents, until the callback return true.</p>
  36. <p class="highlight_red">If returns false, zTree will not set the input box to get focus to avoid the
  37. warning message which led to repeated triggering ‘beforeRename’ callback. Please use editName() method
  38. to set the input box to get focus when user close the warning message.</p>
  39. </div>
  40. <h3>Examples of setting & function</h3>
  41. <h4>1. the length of the new name can't less than 5</h4>
  42. <pre xmlns=""><code>function myBeforeRename(treeId, treeNode, newName, isCancel) {
  43. return newName.length > 5;
  44. }
  45. var setting = {
  46. edit: {
  47. enable: true
  48. },
  49. callback: {
  50. beforeRename: myBeforeRename
  51. }
  52. };
  53. ......</code></pre>
  54. </div>
  55. </div>