[Xsltforms-support] Cancelling loop/action
Brought to you by:
alain-couthures
From: Josselin M. <mor...@gm...> - 2021-02-03 14:33:42
|
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. |