xf:setvalue after xf:insert does not set value in current model

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

xf:setvalue after xf:insert does not set value in current model

jaygo
Hi,
In the following example I've used 6 different ways of setting value into model node. Tests 1 and 5 works fine, but tests 2-4 and 6 does not. Even though the value is set (somewhere) in every situation and can be presented by xf:message action it is not available in current model (neither by any xforms control nor xforms-inspector).

It looks like references to nodes were calculcated way before use and points at a node that is not in current model after xf:insert action. Fifth method could be a temporary solution for me but does not work when it is used inside dispatched custom event - test 6, and that's my case unfortunately.

<xh:html xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xxf="http://orbeon.org/oxf/xml/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fr="http://orbeon.org/oxf/xml/form-runner">
  <xh:head>
    <xh:title>insert and setvalue</xh:title>
    <xf:model>
      <xf:instance id="main">
        <root xmlns="">
          <entry/>
        </root>
      </xf:instance>
      <xf:instance id="copy">
        <root xmlns="">
          <entry/>
        </root>
      </xf:instance>
    </xf:model>
  </xh:head>
  <xh:body>
    <xh:p>
      <xf:group ref="/root/entry" id="group">
        <xf:trigger>
          <xf:label>Test 1</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:setvalue ref="." value="'test 1'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 2</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:setvalue ref="../entry" value="'test 2'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 3</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
          </xf:action>
          <xf:action ev:event="DOMActivate">
            <xf:setvalue ref="../entry" value="'test 3'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 4</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:refresh />
            <xf:setvalue ref="../entry" value="'test 4'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 5</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:refresh />
          </xf:action>
          <xf:action ev:event="DOMActivate">
            <xf:setvalue ref="../entry" value="'test 5'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 6</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:dispatch target="group" name="custom-event" />
          </xf:action>
        </xf:trigger>
        <xf:action ev:event="custom-event">
          <xf:action>
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:refresh />
          </xf:action>
          <xf:action>
            <xf:setvalue ref="../entry" value="'test 6'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:action>
      </xf:group>
    </xh:p>
    <xh:p>
      <xf:output value="if (normalize-space(/root/entry) = '') then '' else concat('Not empty: ', /root/entry, '!')"/>
    </xh:p>
    <fr:xforms-inspector />
  </xh:body>
</xh:html>




--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/fdb44ac6-4165-4e64-bb18-41ca92ab1a63%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: xf:setvalue after xf:insert does not set value in current model

Jarosław Kowalewski
Hi,
just for curiosity, I run the code and check if it is possible to fix it. 
It was possible by adding binds and a reference to xf:message via bind="bind-id" instead of ref. 

Of course, it's not an explanation, but I also have experience with delay in recalculation when use ref attribute. 

BR,
//Jarek

See working code below:
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xxf="http://orbeon.org/oxf/xml/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fr="http://orbeon.org/oxf/xml/form-runner">
  <xh:head>
    <xh:title>insert and setvalue</xh:title>
    <xf:model>
      <xf:instance id="main">
        <root xmlns="">
          <entry>Initial value</entry>
        </root>
      </xf:instance>
      <xf:instance id="copy">
        <root xmlns="">
          <entry/>
        </root>
      </xf:instance>
 
 <xf:bind id="main-bind" ref="instance('main')">
<xf:bind id="entry-bind" ref="entry"/>
 </xf:bind>
 
    </xf:model>
  </xh:head>
  <xh:body>
    <xh:p>
      <xf:group ref="instance('main')/entry" id="group">
        <xf:trigger>
          <xf:label>Test 6</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:dispatch target="group" name="custom-event" />
          </xf:action>
        </xf:trigger>
        <xf:action ev:event="custom-event">
          <xf:action>
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
<xf:setvalue ref="instance('main')/entry" value="now()" />
<xf:rebuild/>
          </xf:action>
          <xf:action>
            <xf:message bind="entry-bind" />
          </xf:action>
        </xf:action>
      </xf:group>
    </xh:p>
    <xh:p>
      <xf:output value="if (normalize-space(/root/entry) = '') then '' else concat('Not empty: ', /root/entry, '!')"/>
    </xh:p>
    <fr:xforms-inspector />
  </xh:body>
</xh:html>

śr., 30 paź 2019 o 13:04 Sławomir Kisiel <[hidden email]> napisał(a):
Hi,
In the following example I've used 6 different ways of setting value into model node. Tests 1 and 5 works fine, but tests 2-4 and 6 does not. Even though the value is set (somewhere) in every situation and can be presented by xf:message action it is not available in current model (neither by any xforms control nor xforms-inspector).

It looks like references to nodes were calculcated way before use and points at a node that is not in current model after xf:insert action. Fifth method could be a temporary solution for me but does not work when it is used inside dispatched custom event - test 6, and that's my case unfortunately.

  <xh:head>
    <xh:title>insert and setvalue</xh:title>
    <xf:model>
      <xf:instance id="main">
        <root xmlns="">
          <entry/>
        </root>
      </xf:instance>
      <xf:instance id="copy">
        <root xmlns="">
          <entry/>
        </root>
      </xf:instance>
    </xf:model>
  </xh:head>
  <xh:body>
    <xh:p>
      <xf:group ref="/root/entry" id="group">
        <xf:trigger>
          <xf:label>Test 1</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:setvalue ref="." value="'test 1'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 2</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:setvalue ref="../entry" value="'test 2'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 3</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
          </xf:action>
          <xf:action ev:event="DOMActivate">
            <xf:setvalue ref="../entry" value="'test 3'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 4</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:refresh />
            <xf:setvalue ref="../entry" value="'test 4'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 5</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:refresh />
          </xf:action>
          <xf:action ev:event="DOMActivate">
            <xf:setvalue ref="../entry" value="'test 5'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 6</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:dispatch target="group" name="custom-event" />
          </xf:action>
        </xf:trigger>
        <xf:action ev:event="custom-event">
          <xf:action>
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:refresh />
          </xf:action>
          <xf:action>
            <xf:setvalue ref="../entry" value="'test 6'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:action>
      </xf:group>
    </xh:p>
    <xh:p>
      <xf:output value="if (normalize-space(/root/entry) = '') then '' else concat('Not empty: ', /root/entry, '!')"/>
    </xh:p>
    <fr:xforms-inspector />
  </xh:body>
</xh:html>




--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/fdb44ac6-4165-4e64-bb18-41ca92ab1a63%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/CAHFpwcWzvcSAht04iS%2BbF4KCfZzA5yYhrsV4Dq7hgZyhjtkkNA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: xf:setvalue after xf:insert does not set value in current model

jaygo
Hi,
Unfortunately xf:bind has some disadvantage that bothers me. It does not work well with repeats because it always goes through first nodes. Ref's works better in such case but worse in case of inserting instance.

W dniu piątek, 1 listopada 2019 15:40:08 UTC+1 użytkownik Jarek napisał:
Hi,
just for curiosity, I run the code and check if it is possible to fix it. 
It was possible by adding binds and a reference to xf:message via bind="bind-id" instead of ref. 

Of course, it's not an explanation, but I also have experience with delay in recalculation when use ref attribute. 

BR,
//Jarek

See working code below:
<xh:html xmlns:xh="<a href="http://www.w3.org/1999/xhtml" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFPnvHmzp7QdvEjpI1OxPKiChMEFw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFPnvHmzp7QdvEjpI1OxPKiChMEFw&#39;;return true;">http://www.w3.org/1999/xhtml" xmlns:xf="<a href="http://www.w3.org/2002/xforms" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F2002%2Fxforms\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFsT85FCBgT3Vtrgkvw8OwGlGHT8w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F2002%2Fxforms\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFsT85FCBgT3Vtrgkvw8OwGlGHT8w&#39;;return true;">http://www.w3.org/2002/xforms" xmlns:xxf="<a href="http://orbeon.org/oxf/xml/xforms" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forbeon.org%2Foxf%2Fxml%2Fxforms\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFYjEz7mP5L4ajuRx6GqLj9iCyivQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forbeon.org%2Foxf%2Fxml%2Fxforms\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFYjEz7mP5L4ajuRx6GqLj9iCyivQ&#39;;return true;">http://orbeon.org/oxf/xml/xforms" xmlns:ev="<a href="http://www.w3.org/2001/xml-events" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F2001%2Fxml-events\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFff_qDKy8FnFbQ86MbMH1vwe7NKw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F2001%2Fxml-events\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFff_qDKy8FnFbQ86MbMH1vwe7NKw&#39;;return true;">http://www.w3.org/2001/xml-events" xmlns:xs="<a href="http://www.w3.org/2001/XMLSchema" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNETUl7MhKy2nWpH8V8BwGakc8etag&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNETUl7MhKy2nWpH8V8BwGakc8etag&#39;;return true;">http://www.w3.org/2001/XMLSchema" xmlns:fr="<a href="http://orbeon.org/oxf/xml/form-runner" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forbeon.org%2Foxf%2Fxml%2Fform-runner\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFIhsOO7At2JqHaGk5a2HYUXk_bVQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forbeon.org%2Foxf%2Fxml%2Fform-runner\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFIhsOO7At2JqHaGk5a2HYUXk_bVQ&#39;;return true;">http://orbeon.org/oxf/xml/form-runner">
  <xh:head>
    <xh:title>insert and setvalue</xh:title>
    <xf:model>
      <xf:instance id="main">
        <root xmlns="">
          <entry>Initial value</entry>
        </root>
      </xf:instance>
      <xf:instance id="copy">
        <root xmlns="">
          <entry/>
        </root>
      </xf:instance>
 
 <xf:bind id="main-bind" ref="instance('main')">
<xf:bind id="entry-bind" ref="entry"/>
 </xf:bind>
 
    </xf:model>
  </xh:head>
  <xh:body>
    <xh:p>
      <xf:group ref="instance('main')/entry" id="group">
        <xf:trigger>
          <xf:label>Test 6</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:dispatch target="group" name="custom-event" />
          </xf:action>
        </xf:trigger>
        <xf:action ev:event="custom-event">
          <xf:action>
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
<xf:setvalue ref="instance('main')/entry" value="now()" />
<xf:rebuild/>
          </xf:action>
          <xf:action>
            <xf:message bind="entry-bind" />
          </xf:action>
        </xf:action>
      </xf:group>
    </xh:p>
    <xh:p>
      <xf:output value="if (normalize-space(/root/entry) = '') then '' else concat('Not empty: ', /root/entry, '!')"/>
    </xh:p>
    <fr:xforms-inspector />
  </xh:body>
</xh:html>

śr., 30 paź 2019 o 13:04 Sławomir Kisiel <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="4DPPo_GIAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">slawomi...@...> napisał(a):
Hi,
In the following example I've used 6 different ways of setting value into model node. Tests 1 and 5 works fine, but tests 2-4 and 6 does not. Even though the value is set (somewhere) in every situation and can be presented by xf:message action it is not available in current model (neither by any xforms control nor xforms-inspector).

It looks like references to nodes were calculcated way before use and points at a node that is not in current model after xf:insert action. Fifth method could be a temporary solution for me but does not work when it is used inside dispatched custom event - test 6, and that's my case unfortunately.

<xh:html xmlns:xh="<a href="http://www.w3.org/1999/xhtml" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFPnvHmzp7QdvEjpI1OxPKiChMEFw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFPnvHmzp7QdvEjpI1OxPKiChMEFw&#39;;return true;">http://www.w3.org/1999/xhtml" xmlns:xf="<a href="http://www.w3.org/2002/xforms" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F2002%2Fxforms\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFsT85FCBgT3Vtrgkvw8OwGlGHT8w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F2002%2Fxforms\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFsT85FCBgT3Vtrgkvw8OwGlGHT8w&#39;;return true;">http://www.w3.org/2002/xforms" xmlns:xxf="<a href="http://orbeon.org/oxf/xml/xforms" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forbeon.org%2Foxf%2Fxml%2Fxforms\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFYjEz7mP5L4ajuRx6GqLj9iCyivQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forbeon.org%2Foxf%2Fxml%2Fxforms\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFYjEz7mP5L4ajuRx6GqLj9iCyivQ&#39;;return true;">http://orbeon.org/oxf/xml/xforms" xmlns:ev="<a href="http://www.w3.org/2001/xml-events" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F2001%2Fxml-events\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFff_qDKy8FnFbQ86MbMH1vwe7NKw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F2001%2Fxml-events\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFff_qDKy8FnFbQ86MbMH1vwe7NKw&#39;;return true;">http://www.w3.org/2001/xml-events" xmlns:xs="<a href="http://www.w3.org/2001/XMLSchema" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNETUl7MhKy2nWpH8V8BwGakc8etag&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNETUl7MhKy2nWpH8V8BwGakc8etag&#39;;return true;">http://www.w3.org/2001/XMLSchema" xmlns:fr="<a href="http://orbeon.org/oxf/xml/form-runner" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forbeon.org%2Foxf%2Fxml%2Fform-runner\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFIhsOO7At2JqHaGk5a2HYUXk_bVQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forbeon.org%2Foxf%2Fxml%2Fform-runner\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFIhsOO7At2JqHaGk5a2HYUXk_bVQ&#39;;return true;">http://orbeon.org/oxf/xml/form-runner">
  <xh:head>
    <xh:title>insert and setvalue</xh:title>
    <xf:model>
      <xf:instance id="main">
        <root xmlns="">
          <entry/>
        </root>
      </xf:instance>
      <xf:instance id="copy">
        <root xmlns="">
          <entry/>
        </root>
      </xf:instance>
    </xf:model>
  </xh:head>
  <xh:body>
    <xh:p>
      <xf:group ref="/root/entry" id="group">
        <xf:trigger>
          <xf:label>Test 1</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:setvalue ref="." value="'test 1'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 2</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:setvalue ref="../entry" value="'test 2'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 3</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
          </xf:action>
          <xf:action ev:event="DOMActivate">
            <xf:setvalue ref="../entry" value="'test 3'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 4</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:refresh />
            <xf:setvalue ref="../entry" value="'test 4'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 5</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:refresh />
          </xf:action>
          <xf:action ev:event="DOMActivate">
            <xf:setvalue ref="../entry" value="'test 5'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 6</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:dispatch target="group" name="custom-event" />
          </xf:action>
        </xf:trigger>
        <xf:action ev:event="custom-event">
          <xf:action>
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:refresh />
          </xf:action>
          <xf:action>
            <xf:setvalue ref="../entry" value="'test 6'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:action>
      </xf:group>
    </xh:p>
    <xh:p>
      <xf:output value="if (normalize-space(/root/entry) = '') then '' else concat('Not empty: ', /root/entry, '!')"/>
    </xh:p>
    <fr:xforms-inspector />
  </xh:body>
</xh:html>




--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="4DPPo_GIAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">orb...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/orbeon/fdb44ac6-4165-4e64-bb18-41ca92ab1a63%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/orbeon/fdb44ac6-4165-4e64-bb18-41ca92ab1a63%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/orbeon/fdb44ac6-4165-4e64-bb18-41ca92ab1a63%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/orbeon/fdb44ac6-4165-4e64-bb18-41ca92ab1a63%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/5c88a93a-25be-4a9e-8a10-061abd0dd43e%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: xf:setvalue after xf:insert does not set value in current model

Jarosław Kowalewski
Not sure what your exact case is but code below works as expected (paste it directly into xh:body). You can add a new entry and edit it. 
<xf:trigger>
      <xf:label>Add item</xf:label>
       <xf:action ev:event="DOMActivate">
          <xf:insert origin="instance('copy')/entry" ref="instance('main')/entry" />
       </xf:action>
    </xf:trigger>
<xf:repeat bind="entry-bind">
<xf:input ref=".">
<xf:label>My entry</xf:label>
</xf:input>
</xf:repeat>

//Jarek

pt., 1 lis 2019 o 16:06 Sławomir Kisiel <[hidden email]> napisał(a):
Hi,
Unfortunately xf:bind has some disadvantage that bothers me. It does not work well with repeats because it always goes through first nodes. Ref's works better in such case but worse in case of inserting instance.

W dniu piątek, 1 listopada 2019 15:40:08 UTC+1 użytkownik Jarek napisał:
Hi,
just for curiosity, I run the code and check if it is possible to fix it. 
It was possible by adding binds and a reference to xf:message via bind="bind-id" instead of ref. 

Of course, it's not an explanation, but I also have experience with delay in recalculation when use ref attribute. 

BR,
//Jarek

See working code below:
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xxf="http://orbeon.org/oxf/xml/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fr="http://orbeon.org/oxf/xml/form-runner">
  <xh:head>
    <xh:title>insert and setvalue</xh:title>
    <xf:model>
      <xf:instance id="main">
        <root xmlns="">
          <entry>Initial value</entry>
        </root>
      </xf:instance>
      <xf:instance id="copy">
        <root xmlns="">
          <entry/>
        </root>
      </xf:instance>
 
 <xf:bind id="main-bind" ref="instance('main')">
<xf:bind id="entry-bind" ref="entry"/>
 </xf:bind>
 
    </xf:model>
  </xh:head>
  <xh:body>
    <xh:p>
      <xf:group ref="instance('main')/entry" id="group">
        <xf:trigger>
          <xf:label>Test 6</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:dispatch target="group" name="custom-event" />
          </xf:action>
        </xf:trigger>
        <xf:action ev:event="custom-event">
          <xf:action>
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
<xf:setvalue ref="instance('main')/entry" value="now()" />
<xf:rebuild/>
          </xf:action>
          <xf:action>
            <xf:message bind="entry-bind" />
          </xf:action>
        </xf:action>
      </xf:group>
    </xh:p>
    <xh:p>
      <xf:output value="if (normalize-space(/root/entry) = '') then '' else concat('Not empty: ', /root/entry, '!')"/>
    </xh:p>
    <fr:xforms-inspector />
  </xh:body>
</xh:html>

śr., 30 paź 2019 o 13:04 Sławomir Kisiel <[hidden email]> napisał(a):
Hi,
In the following example I've used 6 different ways of setting value into model node. Tests 1 and 5 works fine, but tests 2-4 and 6 does not. Even though the value is set (somewhere) in every situation and can be presented by xf:message action it is not available in current model (neither by any xforms control nor xforms-inspector).

It looks like references to nodes were calculcated way before use and points at a node that is not in current model after xf:insert action. Fifth method could be a temporary solution for me but does not work when it is used inside dispatched custom event - test 6, and that's my case unfortunately.

  <xh:head>
    <xh:title>insert and setvalue</xh:title>
    <xf:model>
      <xf:instance id="main">
        <root xmlns="">
          <entry/>
        </root>
      </xf:instance>
      <xf:instance id="copy">
        <root xmlns="">
          <entry/>
        </root>
      </xf:instance>
    </xf:model>
  </xh:head>
  <xh:body>
    <xh:p>
      <xf:group ref="/root/entry" id="group">
        <xf:trigger>
          <xf:label>Test 1</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:setvalue ref="." value="'test 1'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 2</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:setvalue ref="../entry" value="'test 2'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 3</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
          </xf:action>
          <xf:action ev:event="DOMActivate">
            <xf:setvalue ref="../entry" value="'test 3'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 4</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:refresh />
            <xf:setvalue ref="../entry" value="'test 4'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 5</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:refresh />
          </xf:action>
          <xf:action ev:event="DOMActivate">
            <xf:setvalue ref="../entry" value="'test 5'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:trigger>
        <xf:trigger>
          <xf:label>Test 6</xf:label>
          <xf:action ev:event="DOMActivate">
            <xf:dispatch target="group" name="custom-event" />
          </xf:action>
        </xf:trigger>
        <xf:action ev:event="custom-event">
          <xf:action>
            <xf:var name="param" value="." />
            <xf:insert origin="instance('copy')" ref="instance('main')" />
            <xf:refresh />
          </xf:action>
          <xf:action>
            <xf:setvalue ref="../entry" value="'test 6'" />
            <xf:message value="../entry" />
          </xf:action>
        </xf:action>
      </xf:group>
    </xh:p>
    <xh:p>
      <xf:output value="if (normalize-space(/root/entry) = '') then '' else concat('Not empty: ', /root/entry, '!')"/>
    </xh:p>
    <fr:xforms-inspector />
  </xh:body>
</xh:html>




--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/fdb44ac6-4165-4e64-bb18-41ca92ab1a63%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/5c88a93a-25be-4a9e-8a10-061abd0dd43e%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/CAHFpwcXHyUer66CAtk6Jzq5W0K8c5KWr0_YL3AizDydqe55axQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: xf:setvalue after xf:insert does not set value in current model

Alessandro  Vernet
Administrator
In reply to this post by jaygo
Hi,

Interesting cases. It looks like things are not working as they should, but,
in fact, they do ;). Let's go through it:

1) "test 1" is set in the instance and shows in the message, good.

2) Actions evaluate in a certain context. Since you have an `<xf:action
ev:event="DOMActivate">` inside a `<xf:trigger>`, the context is the node
the trigger is bound to, which in your case is `/root/entry` of the first
`main` instance. You start by doing a `<xf:insert origin="instance('copy')"
ref="instance('main')"/>`. When you do an insert with a `ref` pointing to
the root element if the instance, it replaces that element. That is the
interesting part: after the insert, `instance('main')` contains a new copy
of `instance('copy')`, which looks exactly the same, but is a different
copy. Meanwhile, the context isn't changed: it just points to a node that
now isn't reachable through an instance, and thus will be garbage collected
if not inserted somewhere before the end of the action. So now you
`<xf:setvalue ref="../entry" value="'test 2'"/>`, which sets the value in
that "detached" tree. `<xf:message value="../entry"/>` shows the value you
inserted, but at the end that value isn't in `instance('main')`.

3) This behaves the same as the previous one even if you have a separate
event handler. This is because the node the `<xf:trigger>` is bound to isn't
reevaluate between event dispatches; it is only reevaluate when the UI is
refreshed.

4) The `<xf:refresh/>` does reevaluate the node bound to the `<xf:trigger>`,
but the action is still running, so it keeps it current context (the
"detached node").

5) This one works, because you have a different event handler, which takes
the new context of the `<xf:trigger>`, which has been reevaluated by your
`<xf:refresh/>`.

6) Is equivalent to 4.

And of course, just let me know if anything isn't clear, or this doesn't
give you enough information to solve the actual case you are dealing with.

‑Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/1572892915468-0.post%40n4.nabble.com.
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: xf:setvalue after xf:insert does not set value in current model

Alessandro  Vernet
Administrator
Hi Sławomir, did you finally manage to do what you were looking for,
inserting a subtree in your instance needed? And of course, just let me know
if anything in the use cases you mentioned still doesn't make sense.

‑Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/1573495138084-0.post%40n4.nabble.com.
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet