HTTPS SSH

Tree Widget for jQuery Tree Multiselect

This is a sample Django app, that provides jQuery Tree Multiselect widget.

Module is intendet to be used as a Django application. Standalone usage is very limited. See :ref:`Integration <integration>` for details.

Integration

Integration is very simple:

  1. Add this module to your :file:`setup.py` or requirements file:
# setupy.py:
install_requires = [
                    ..
                    tree_widget
                    ..]
  1. Include this app to your applications in :file:`settings.py`:
INSTALLED_APPS = [
                  ..
                  tree_widget.apps.tree
                  ..
                 ]
  1. You should import and use :class:`tree_widget.apps.tree.models.Tree` in your code.
  2. You can use :class:`tree_widget.apps.tree.forms.TreeMultipleChoiceField` form field in your forms:
from django improt forms
from tree_widget.apps.tree.models import Tree
from tree_widget.apps.tree.forms import TreeMultipleChoiceField
from tree_widget.apps.tree.helpers import generate_struct_iterator


class TreeForm(forms.Form):
    tree_field = TreeMultipleChoiceField(choices=generate_struct_iterator(Tree.objects.all()))

If used in template, this field should add all required statics and initialization to markup.

Notes

<link href="/static/tree_field/css/jquery.tree-multiselect.css" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/static/tree_field/js/jquery.js"></script>
<script type="text/javascript" src="/static/tree_field/js/jquery.tree-multiselect.js"></script>

<select multiple="multiple" data-tree-select="true" id="id_tree_field" name="tree_field" required>
        ...
</select>
<script type="text/javascript">
        var params = {}
        $('#id_tree_field').treeMultiselect(params);
</script>

License

See :doc:`LICENSE.txt` for details.

Part of the code comes from tree.multiselect.js:, which is licensed under MIT License:

Copyright (c) 2015 Patrick Tsai et al.