AlainCouthures / xsltforms

XForms to XHTML+Javascript (AJAX) conversion based on a unique XSL transformation. Suitable server-side (PHP) or client-side (Google Chrome, Edge, Internet Explorer, Mozilla FireFox, Opera, Safari) browser treatment where an XSLT 1.0 engine is available
37 stars 17 forks source link

Events not getting raised on subform element? #8

Closed ashalkhakov closed 9 years ago

ashalkhakov commented 9 years ago

Hello,

I have a form sketch where subforms are embedded into the main form. However, there are complications:

  1. if subform failed to be found, then the user should be notified about the error
  2. user has to be able to dismiss the subform either by accepting or rejecting it

Here's the main form (showform3_load.xml):

<?xml-stylesheet href="/xsltforms/xsltforms.xsl" type="text/xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:xforms="http://www.w3.org/2002/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events">
  <head>
    <title>Main Form</title>
    <xforms:model>
      <xforms:instance>
        <data xmlns=""/>
      </xforms:instance>
      <!-- FIXME: these actions are only run once (probably get removed on subform unload?) -->
      <xforms:action ev:event="xforms-link-exception" ev:observer="subform">
        <xforms:message>
          Failed to obtain the subform at: <xforms:output value="event('resource-uri')"/>,
          error code: <xforms:output value="event('response-status-code')"/>,
          error reason: <xforms:output value="event('response-reason-phrase')"/>
        </xforms:message>
      </xforms:action>
      <xforms:action ev:event="xforms-load-done" ev:observer="subform">
        <xforms:message>Load Success!</xforms:message>
        <xforms:toggle case="form-sub"/>
      </xforms:action>
    </xforms:model>
  </head>
  <body>
    <xforms:switch id="form-switch">
      <!-- this is the "main" form -->
      <xforms:case id="form-main">
        <h2>Main form</h2>
        <xforms:trigger>
          <xforms:label>Open subform 1</xforms:label>
          <xforms:action ev:event="DOMActivate">
            <xforms:message>Opening subform 1</xforms:message>
            <xforms:load show="embed" targetid="subform" resource="showform3_subform1.xml"/>
          </xforms:action>
        </xforms:trigger>
        <xforms:trigger>
          <xforms:label>Open subform 2</xforms:label>
          <xforms:action ev:event="DOMActivate">
            <xforms:message>Opening subform 2</xforms:message>
            <xforms:load show="embed" targetid="subform" resource="showform3_subform2.xml"/>
          </xforms:action>
        </xforms:trigger>
      </xforms:case>
      <!-- this is the portion of the form that we will be using for subforms (e.g. Edit subform) -->
      <xforms:case id="form-sub">
        <xforms:trigger>
          <xforms:label>Accept Subform</xforms:label>
          <xforms:action ev:event="DOMActivate">
            <xforms:message>Accepting Subform</xforms:message>
            <xforms:unload targetid="subform"/>
            <xforms:toggle case="form-main"/>
          </xforms:action>
        </xforms:trigger>
        <!-- this actually does what we want, but the subform *by itself*
           is invalid (there is no such targetid in the subform!
        -->
        <xforms:trigger>
          <xforms:label>Reject Subform</xforms:label>
          <xforms:action ev:event="DOMActivate">
            <xforms:message>Rejecting Subform</xforms:message>
            <xforms:unload targetid="subform"/>
            <xforms:toggle case="form-main"/>
          </xforms:action>
        </xforms:trigger>
        <xforms:group id="subform"/>
      </xforms:case>
    </xforms:switch>
  </body>
</html>

Here is subform 1 (showform3_subform1.xml):

<?xml-stylesheet href="/xsltforms/xsltforms.xsl" type="text/xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:xforms="http://www.w3.org/2002/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events">
  <head>
    <title>Subform 1</title>
    <xforms:model>
      <xforms:instance>
        <data xmlns=""/>
      </xforms:instance>
    </xforms:model>
  </head>
  <body>
    <h2>Subform 1</h2>
    <p>hello world!</p>
  </body>
</html>

And finally, here is subform 3 (showform3_subform2.xml):

<?xml-stylesheet href="/xsltforms/xsltforms.xsl" type="text/xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:xforms="http://www.w3.org/2002/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events">
  <head>
    <title>Subform 2</title>
    <xforms:model>
      <xforms:instance>
        <data xmlns=""/>
      </xforms:instance>
    </xforms:model>
  </head>
  <body>
    <h2>Subform 2</h2>
    <p>goodbye world!</p>
  </body>
</html>

To reproduce:

  1. Open the main form
  2. Click on "Open subform 1"
  3. Subform 1 will be opened
  4. Click on "Accept Subform"
  5. You will be brought back to the main form
  6. Click on either "Open subform 1" or "Open subform 2", and there is no change

Please help me figure this one out.

ashalkhakov commented 9 years ago

Forgot to say that I'm using XSLTForms 1.0RC2.

ashalkhakov commented 9 years ago

Tim Thompson helped with this one. Please see his posting to the mailing list:

https://sourceforge.net/p/xsltforms/mailman/message/34273447/

Closing.