OK, so the 'partial' checking of checkboxes I can understand as being rather specific.

How about where a checkbox tree is put in a form to replace (for example) a multi-select select list or other list of options?

I don't see anything in your code to ensure that when the form is submitted, the checked items are sent in the POST or GET parameters.

I can't see that this is 'very-very' specific. Quite a few people must be doing this.

But hey, it's your code you can do what you want (or not) with it.

A further enhancement appears to be as follows.

The checked tree object is used to replace a select list that is within a form.

When the form is submitted, a call to a new method, makeFormElements, is made which will inject 'input' elements into the form and give them the name of the select list and a value for each of the tree elements which is checked.

This allows the server to process the checked items in the mif-tree as if they were items from a multi-select list.

Again, I can offer you this code when I have tidied it up.

Sorry to pollute your message board but as is often the case, sometimes you think of the answer after you have posted a question!

I checked back through our source-code repository and found that the previous programmer (may he rot in hell!) had made modifications to the original mif-tree code rather than extending it!

Anyway, the functionality I have may be of interest to you so I will try to explain it.

[img]checkboxes.gif[/img]

The idea is that clicking a parent does not check all children (as the 'simple' option works I believe)

Clicking a child however will check all parents (but put them in a 'disabled' mode)

This is for use in the circumstance where it only makes sense for children to be checked if all ancestors are also checked.

The code that used to work has the following

initialize: function(){
    this.initCheckbox('partial', 'id', tFormField);
},

and I note that in my original copy of mif-tree, Mif.Tree.Checkbox.js it checked for type=='partial' but that this is missing in the latest version.

Has this functionality been removed?

Or re-thinking this. I took over this project from another programmer. I wonder if it is something that he did and he modified the code directly?

If so may-be you would be interested in a patch?

I had to upgrade to the latest mif-tree.

On a checkbox tree, previously if I clicked a parent node (with the tree opened to show the children) it would only check the parent.

Now if I click the parent all the children are checked as well.

I don't know if it was as a result of the upgrade of mif-tree or some other change to my code that I did at the same time.

Is the operation of this something that can be configured?

Regards
Icydee

6

(3 replies, posted in Help)

moro
Thanks for your prompt reply. I *think* I might have understood it but it seemed too complicated to implement (if I understood it correctly)

Anyway, after a major re-work of my code I have decided to change the back-end code so that the whole of the tree is pre-loaded and there are now no longer any AJAX calls to get the children nodes. The pre-loaded JSON has the 'checked' values for those checkboxes I want to be checked.

I now almost have a working system but something is different in terms of the way checking boxes works, but I will cover that in a separate thread so as not to change the subject of this thread. smile

I have been trying to understand/fix this now for three days mad

I have a page rather like the demo 'Tree simple checkboxes' so that as each node is opened up an AJAX call is made to retrieve the next section of the tree.

My understanding is that if I call setChecked, which recursively navigates the tree looking for the node to check, it will not be able to check a node that has not yet been loaded. (Seems reasonable).

So if when I display a page where there is a checkbox tree with some boxes I want to check (even if they are not yet opened up) I have to load the whole tree? (Or at least those portions of the tree that need to be checked).

So, what I want is code that allows me to preload the whole tree, then I can make a call to setChecked.

However, it seems that I need to make a call to tree.loadOptions and this over-writes any checked values, and I can't get my page to open nodes if I leave it out!

        function setupTree(data,tContainer,tFormField,tTreeData,tAjaxUri) {
            var tree = new Mif.Tree({
                container:      $(tContainer),
                forest:         true,                               // tree does not have a root node
                initialize:     function() {
                    $(tFormField).dispose();
                    this.initCheckbox('partial', 'id', tFormField);
                },
                types: {
                    folder: {
                        openIcon:       'mif-tree-open-icon',
                        closeIcon:      'mif-tree-close-icon'
                    },
                    loader: {
                        openIcon:       'mif-tree-loader-open-icon',
                        closeIcon:      'mif-tree-loader-close-icon',
                        DDnotAllowed:   ['inside','after']
                    }
                },
                dfltType:       'folder',
                height:         18
            });

            tree.load({json: data[tTreeData]});

            tree.loadOptions=function(node){
                var options = {};
                if (node.id) {
                    options.url = tAjaxUri+node.id;
                }
                return options;
            }

            if (data && data.form_values && data.form_values[tFormField])
            {
                tree.setChecked(data.form_values[tFormField]);
            }
            tree.openLoaded();
            return tree;
        }