Create to treeLeaf

Hello,

I want to create a treeLeaf with a selected date on a calendar. The problem is that I create a treeLeaf empty, without text.I have this:

<div>
        <b:calendar name="Calendario" id="elCalendario"/>
</div>

 <d:behavior name="addLeaf">
    <d:handler event="mouseup">
       <e:set variable="tFecha" select="id('elCalendario')/property::value" />
         <e:if test="id('contextMenuTree1')/property::selectedNode">
             <c:create destination="id('contextMenuTree1')/property::selectedNode">
                <b:treeLeaf label="" id="nuevoNodo"> </b:treeLeaf>  
             </c:create>
             <c:setText select="$tFecha" destination="id('nuevoNodo')"        mode="firstChild">
             </c:setText>
         </e:if>
   </d:handler>
 </d:behavior>




Thank you.

create to treeleaf

Hi,

There two possible reasons why your code doesn't work.

1. If you want to create a b:treeLeaf with text content, you should set the 'label' attribute on it instead of appending a text node for it. In your case, the code could be like:

 <c:setAttribute with="id('nuevoNodo')" name="label" select="$tFecha" />

2. A tricky problem of the triggering order of event handlers. In your code, you tried to get the current value of calender when 'mouseup' event happens. However, the b:calendar itself also depends on this event to update its data. Unfortunately, the order that these two handlers are executed is not predictable. In your case, when your 'mouseup' event handler is invoked, the new date of calender has not been set yet. We can use a trick to achieve this, here is the code:

<d:behavior name="addLeaf">
         <d:method name="createLeaf">
                <d:body type="application/xml">
                        <e:set variable="tFecha" select="id('elCalendario')/property::value" />
                        <e:if test="id('contextMenuTree1')/property::selectedNode">
                                 <c:create destination="id('contextMenuTree1')/property::selectedNode">
                                        <b:treeLeaf label="" id="nuevoNodo"></b:treeLeaf>
                                 </c:create>
                                 <c:setAttribute with="id('nuevoNodo')" name="label" select="$tFecha" />
                   </e:if>
                </d:body>
         </d:method>
         <d:handler event="mouseup" type="application/javascript">
                 function createLeaf(){
                         call(bb.getElementById('elCalendario')).createLeaf();
                 };
                 setTimeout(createLeaf, 0);//trick to delay the invoking
         </d:handler>
</d:behavior>

And of course, don't forget to attach the behavior to your b:calendar

<b:calendar name="Calendario" id="elCalendario" e:behavior="xx:addLeaf"/>