One way would be to submit just one, and let the xforms-submit-done event 
handler initiate the next.


<submission id="submitNewEntity" blabla>
    <action ev:event="xforms-submit-done">
        <dispatch name="NEXT" targetid="M"/>
    </action>
</submission>


<action ev:event="NEXT">
    <send submission="submitNewEntity"/>
</action>



<trigger>
   <label>save</label>
   <action ev:event="DOMActivate">
       <send submission="submitNewEntity"/>
   </action>
</trigger>


Steven

On Wednesday 03 February 2021 15:33:21 (+01:00), Josselin Morvan wrote:


Hi all, 


With one of my forms I have a « submission loop » and I try, when I get an « 
xforms-submit-error », to stop the loop, do you know how we can do that ?.


Basically, my form concerns a list of person. I can add informations about the 
existing ones and, of course, add new persons.


Each « new person » is saved individually, and for this I use a loop : 


<xf:trigger>
    <xf:label>save</xf:label>
    <xf:action 
        ev:event="DOMActivate" 
        while="instance('xprEntities')/xpr:entity[@localType = 'new']">
            <xf:send submission="submitNewEntity"/>
    </xf:action>
</xf:trigger>


When the submission is done, I update my instance with my server’s response and 
I change the @localType value to ’stored’, and then the loop submit the next 
entity.


<xf:submission mode="synchronous"
               id="submitNewEntity"
               
ref="instance('xprEntities')/xpr:entity[@localType='new'][1]/eac:eac-cpf"
               resource="/xpr/biographies/put"
               method="put"
               replace="none">
    <xf:action ev:event="xforms-submit-done">
        <xf:message level="modal">Entity Saved!</xf:message>
        <xf:setvalue 
ref="instance('xprEntities')/xpr:entity[@xml:id=normalize-space(event('response-body')//xpr:xforms-id)]/@xml:id"
 
                     value="event('response-body')//xpr:id"/>
        <xf:setvalue 
ref="instance('xprEntities')/xpr:entity[@xml:id=normalize-space(event('response-body')//xpr:id)]/@localType"
 
                     value="'stored'"/>
        <xf:delete 
nodeset="instance('xprEntities')/xpr:entity[@xml:id=normalize-space(event('response-body')//xpr:id)]/eac:eac-cpf"/>
    </xf:action>
        <xf:action ev:event="xforms-submit-error">
            <xf:message level="modal">Error</xf:message>
        </xf:action>
</xf:submission>




Here is my issue, when an xforms-submit-error occurs, by example because the 
name is required and is not filled, I’d like to stop the submission loop. For 
now, it is looping endlessly, as the @localType of current entity won’t be 
modified until the submission will be done…


I tried to use ev:defaultAction="cancel" with the xf:action in the save trigger 
but it doesn’t work and I think I don’t use it properly!


<xf:trigger>
    <xf:label>save</xf:label>
    <xf:action
        ev:event="DOMActivate"
        while="instance('xprEntities')/xpr:entity[@localType = 'new']">
        <xf:action ev:event="xforms-submit-error" 
                   ev:defaultAction="cancel">
            <xf:send submission="submitNewEntity"/>
        </xf:action>
    </xf:action>
</xf:trigger>
(I also tried this on the xf:send without success).


Do you have any idea to achieve this or how to use ev:defaultAction ?


I know I could add an incrementation system in my loop, (adding +1 to an 
iterator instance when xforms-submit-done or xforms-submit-error occurs, and 
submitting the next entity with position() = instance(‘iterator’)), but I’d 
like to avoid this way of proceeding.


Thanks a lot for you help, best, 
Josselin.  

-- 
_______________________________________________
Xsltforms-support mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xsltforms-support

Reply via email to