Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submit Checkboxes to form #31

Open
trymeouteh opened this issue Apr 4, 2023 · 1 comment
Open

Submit Checkboxes to form #31

trymeouteh opened this issue Apr 4, 2023 · 1 comment

Comments

@trymeouteh
Copy link

Is it possible for the tree to use checkboxes to allow for the tree values to be submitted in a form?

@THenkeDE
Copy link

you could easily do that using the onChange method of the tree itself:

html:

<form ...>
    <input id="selectednodesformfield" type="hidden" name="selectednodes" />
</form>

js:

	let selectedNodes = [];
	let tree = new Tree('<selector>', {

		...,
        onChange: function() {
            selectedNodes = [];
            this.selectedNodes.forEach( function(node){
                selectedTree.push(node.id);
            });
            document.getElementById('#selectednodesformfield').value = JSON.stringify(selectedNodes);
        },
        ...
    });

Now you have an JSON encoded string of all node Ids in a formfield and you can work with that at the target of your form submission.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants