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 developer advocate for HERE Technologies. He focuses on JavaScript, serverless 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