kartik-v / yii2-tree-manager

An advanced tree management module using nested sets for Yii 2.
http://demos.krajee.com/tree-manager
Other
150 stars 107 forks source link

Option to prevent children for certain nodes #197

Closed adhayward closed 6 years ago

adhayward commented 6 years ago

First up this control is brilliant and so close to what I need for my project. In my setup however, I really need to distinguish between 'files' and 'folders'. If a file is selected then it shouldn't be possible to add any children, but if a folder is selected then it should be allowed.

I've attempted to handle this in the treeview.selected event but I'm finding that the first time I click on a node it works but any time after that the sequence of events is off and my event handler is called before the treeview select function calls enableToolbar() which then overrides anything I change.

I'd rather not create my own version of kv-tree.js so I can stay up to date easily

I see two potential fixes

  1. Move the self.raise('treeview.selected') to the end of the select function as it currently can fire before the item is finished selecting and perhaps where it currently is add a selecting event
  2. Add a new flag to go with the moveable-u/d/l/r, removeable that controls whether the create button is enabled for a menu item in the same way as the existing flags do.

Essentially I'm trying to achieve 2 myself now but can't due to the selected event firing too soon on it's second click.

If you want to reproduce the issue with the selected event you can run $('#kvTreeMain').on('treeview.selected', function(event) {$('#kvTreeMain').treeview('disable', 'create');}); in the dev tools console on the demo page http://demos.krajee.com/tree-manager-demo/tree-view This leaves the create button disabled the first time you select each node but when you click back on a node you previously selected, the create button is enabled.

kartik-v commented 6 years ago

Thanks for the feedback. While it can be done via javascript - but I am noting an enhancement to see if it can be done better.