On Thursday 04 February 2021 15:34:27 (+01:00), Josselin Morvan wrote:


Hi Steven, 


Thank you very much for your answer. I don't know why I didn’t think of it 
before, as I use this method with another form… but not for a loop.  
It’s simple and efficient!


Just for my personal understanding, do you know (or anyone else) how works 
ev:defaultAction and if it’s fully implemented with XSLTforms?
<xf:action ev:event="xforms-submit-error" 
           ev:defaultAction="cancel">
       <xf:send submission="submitNewEntity"/>
</xf:action>
What this says is: catch xforms-submit-error, and cancel its default action. 


However, if you look at 
   https://www.w3.org/TR/xforms11/#submit-evt-submit-error 
   or https://homepages.cwi.nl/~steven/xforms/xforms11-qr.html#XForms1 


you'll see that you can't cancel it, because it has no default action. This is 
the case for all notification events: they have no default action.


I'll add a test case to the TestSuite for ev:defaultAction though.


Steven




Thanks a lot, 
Best, 
Josselin.  




Le 4 févr. 2021 à 12:12, Steven Pemberton <[email protected]> a écrit :


I was initially too lazy to check if a handler for submit-done was allowed to 
initiate a submission using the same submission element, but then my shame got 
the better of me and I looked it up. It is, so this is better (and I also added 
the necessary if= that I forgot to add):


<submission id="submitNewEntity" blabla>
    <action ev:event="xforms-submit-done">
        <send if="instance('xprEntities')/xpr:entity[@localType = 'new']" 
submission="submitNewEntity"/>
    </action>
</submission>


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


Steven

On Thursday 04 February 2021 11:58:49 (+01:00), Steven Pemberton wrote:


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