Event xforms-model-construct-done behaviour

2019-09-11 08:42发布

问题:

In my form I would like to call web service after to form is loaded after publishing. I've created custom XBL control for it, where I have :

<xf:group id="component-group">
    <xf:action ev:event="xforms-enabled" ev:target="component-group">
        <xf:send ev:event="xforms-enabled" submission="my-submission"/> 
    </xf:action>
</xf:group>

But it doesn't work as expected : my submission is sent everytime when I add new element in FormBuilder or change a name of some other controls. Generally speaking submission is sent when my form is changing in some way.

Now I want submission to be sent ONLY when I publish my form and someone would open it to fill (and of course when I press "Test" in FormBuilder, but I guess it's the same as filling form after publishing).

I was trying something like this :

<xf:group id="component-group">
    <xf:action ev:event="xforms-model-construct-done" ev:target="component-group">
        <xf:send ev:event="xforms-model-construct-done" submission="my-submission"/> 
    </xf:action> 
</xf:group>

Unfortunately it's not working, this way submission is not sent at all. Any thoughts ?

回答1:

This is due to the fact that XBL components are live at design time too. So you need a way to test whether the component is running within Form Builder or not.

There should be a function for this, really, but there isn't (I added this to the list of functions we should add to the API here). You can do:

<xf:group id="component-group"> <xf:var name="fr-params" value="xxf:instance('fr-parameters-instance')"/> <xf:action event="xforms-enabled" target="component-group" if="not($fr-params/app = 'orbeon' and $fr-params/form = 'builder')"> <xf:send submission="my-submission"/> </xf:action> </xf:group>

A few minor comments:

  • you don't need to (in fact shouldn't) place event attributes on nested actions
  • you don't even need the ev prefix


标签: forms orbeon xbl