Ask a Jedi: Getting stuff from the Ajax Tree, hack of Forta's File Browser Example

This post is more than 2 years old.

Forgive the humongous title there. Cyril asks:

I am trying to create a simple file in chooser in a cfwindow using cftree using Ben's example of filesystem browser, to populate a form field. I can open the window and the tree works fine, but how do I return the value of the node to the input field? I tried to look up ColdFusion.getElementValue but there is very little information on how to use it even on Livedocs.

So first off, here is the demo on Ben's site that Cyril was talking about: ColdFusion Ajax Tutorial 5: File System Browsing With The Tree Control Ben's demos hows a CFC feeding file information to an Ajax based tree. The issue Cyril is having though is in getting the value from the tree.

This actually is covered in the reference guide for getElementValue, but you may have skimmed over it. The third attribute to getElementValue allows you to specify a particular attribute of the element to retrieve the value. This is necessary for Tree's as they have two main values: PATH and NODE. So Cyril simply needs to do something like so:

<script> function test() { var myval = ColdFusion.getElementValue('dirtree','myform','path'); alert(myval); } </script>

<cfform id="myform"> <cftree name="dirtree" format="html"> <cftreeitem bind="cfc:dirtree.getDirEntries({cftreeitempath}, {cftreeitemvalue})"> <cfinput type="button" onclick="test()" name="testbutton" value="Test"> </cftree> </cfform>

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Dan Sorensen posted on 1/8/2008 at 7:56 PM

I <a href="http://blog.dsoren.com/2007...">posted a slightly different way</a> of getting the value of a cftree. Clicking on the tree in my example calls the function and passes in it's own value for a cfwindow rather than an input, but the idea is the same. It's not perfect, but may spark some additional ideas. It's nice to see how you did it here: short and sweet. :-)

Comment 2 by Dan Sorensen posted on 1/8/2008 at 7:59 PM

Oops, I goofed up that last comment. Forgot I shouldn't use html... I said that I posted a slightly different method on my blog: http://blog.dsoren.com/2007...

Comment 3 by Dan Fredericks posted on 9/8/2010 at 8:36 PM

Can anyone help me with the the output from Ben's CFTree example?
When I copy the code to my machine (cfc and cfm), select a folder, and click a button to alert out my value (from ray's code above), it seems like the cfc code will display mulitple items not just the folder i clicked on.

Example:

C
testfolder1
testfolder2
subtestfolder1
subtestfolder2

if in cftree i click down to subtestfolder2, here is the display i get when i dump the myval:

C:\testfolder2\C:\testfolder2subtestfolder2

if you look at Ben's post, one of the last comments, someone asked about this same problem.

thanks
Dan

Comment 4 by Dan Fredericks posted on 9/8/2010 at 9:10 PM

Hey,
so after playing around some, and using node instead of path in the getElementValue, i was able to get the right folder i selected. Not sure why path was an issue, but it was.

dan