How can I disable a custom submit button after submit?
Below you can find my part of code to send:
<xf:trigger bind="booking-bind" id="booking">
<xf:label>
<xh:span>
<xf:output value="'Send'"/>
</xh:span>
</xf:label>
<xf:action ev:event="DOMActivate">
<xf:setvalue ref="instance('fr-form-instance')/submission_type">SendBooking</xf:setvalue>
<xf:setvalue ref="instance('fr-form-instance')/submission_extra_info">//booking[1]</xf:setvalue>
<xf:action type="xpath" xmlns:process="java:org.orbeon.oxf.fr.process.SimpleProcess">
process:runProcessByName('oxf.fr.detail.process', 'send')
</xf:action>
</xf:action>
</xf:trigger>
I am using this solution: Orbeon upgrade from 3.9 to 4.5 : Customized submit for saving forms
I see your trigger has a booking-bind bind. You could have a readonly MIP saying whether the button should be readonly. For example:
<bind id="booking-bind" readonly=". = 'sent'"/>
Then, in your action, do:
<xf:setvalue ref="xxf:bind('booking-bind')" value="'sent'"/>
This will cause the trigger to become readonly.
By the way we have an issue to tackle this better.
Related
<xf:action ev:event="xforms-model-construct">
<xf:insert nodeset="instance('subInstance')/type" origin="instance('defaultType')/type"/>
</xf:action>
I want to populate an instance based on another one. I can do this using xf:insert as shown above.
However, I realised that the instance 'subInstance' must contain an empty type element before starting the xf:inserts.
<subInstance>
<type/>
</subInstance>
So after all the xf:inserts, I need do the following to delete the first empty one:
<xf:delete nodeset="instance('subInstance')/type" at="1" />
Is there something wrong with this method or is there a way I can insert directly without an initial empty ?
Two answers:
You don't really need an initial type element
Your original instance can simply be:
<subInstance/>
And then you can insert into the subInstance element with:
<xf:action ev:event="xforms-model-construct">
<xf:insert
context="instance('subInstance')"
origin="instance('defaultType')/type""/>
</xf:action>
Using context without nodeset or ref says that you want to insert into the node pointed to by context.
You can still do what you want but with XForms 2.0 support
If you want to keep the original nested type element, you could write this:
<xf:action ev:event="xforms-model-construct">
<xf:insert
nodeset="instance('subInstance')"
origin="
xf:element(
'subInstance',
instance('defaultType')/type
)
"/>
</xf:action>
By targeting the root element of the destination instance, the entire instance will be replaced. This is already the case with XForms 1.1.
With the origin attribute's use of the xf:element() function from XForms 2.0, you can dynamically create an XML document rooted at subInstance and containing only the type elements from the defaultType instance.
To make this even more modern, you would replace nodeset with ref, as nodeset is deprecated in XForms 2.0:
<xf:action ev:event="xforms-model-construct">
<xf:insert
ref="instance('subInstance')"
origin="
xf:element(
'subInstance',
instance('defaultType')/type
)
"/>
</xf:action>
In my form file I have a submission load-data-submission which fetches some data from database, it is called on xforms-ready :
<xf:model>
...
<xf:action ev:event="xforms-ready" ev:observer="fr-form-model" if="true()">
<xf:send submission="load-data-submission"/>
</xf:action>
...
</xf:model>
Now, I have an XBL controll which is used in this very same form. There is another submission which also fetches data etc, let's call it rest-submission. Now, I would like the rest-submission (the one inside XBL) to be called right after my load-data-submission (the one inside form file) would fetch data.
How would I do that ? I've tried put inside XBL
<xf:action ev:observer="load-data-submission" ev:event="xforms-submit-done">
<xf:send submission="rest-submission"/>
</xf:action>
with no luck.
Thanks in advance.
To avoid id clashes and enable encapsulation, XBL defines a new lexical scope for ids and a new XPath context. So if from inside the XBL you refer to id load-data-submission, this refers to a load-data-submission defined within the XBL, which is most likely non-existent in your case. To reference ids outside of the XBL, you need to change the scope with the xxbl:scope="outer" attribute. The following example illustrates how to do that:
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xbl="http://www.w3.org/ns/xbl"
xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:example="http://example.com/">
<xh:head>
<xf:model>
<xf:submission
id="get-states"
method="get"
resource="/xforms-sandbox/service/zip-states"
replace="instance"
instance="states"/>
<xf:instance id="states">
<empty/>
</xf:instance>
</xf:model>
<xbl:xbl>
<xbl:binding element="example|simple">
<xbl:implementation>
<xf:model id="simple-model">
<xf:instance>
<internal/>
</xf:instance>
</xf:model>
</xbl:implementation>
<xbl:template>
<xf:group>
<xf:message ev:observer="get-states"
ev:event="xforms-submit-done"
xxbl:scope="outer"
value="'Got event'"/>
</xf:group>
</xbl:template>
</xbl:binding>
</xbl:xbl>
</xh:head>
<xh:body>
<example:simple/>
<xf:trigger>
<xf:label>Get states</xf:label>
<xf:send submission="get-states" ev:event="DOMActivate"/>
</xf:trigger>
</xh:body>
</xh:html>
I would like to send submission after form has been saved in Form Builder, I was trying something like this at first (in my XBL file):
<xf:action ev:event="fr-data-save-done" ev:observer="fr-form-model">
<xf:message event="#all" level="modal">Saved</xf:message>
<xf:send submission="my-submission" ev:event="#all"/>
</xf:action>
The code above is placed in XBL file between xbl:template, outside xbl:model (though I tried to put it inside xbl:model with no luck).
Unfortunately it's not working, after I save my form in Form Builder message is not shown.
Anyone got idea why it's not working?
You could place by hand an event handler like this:
<foo:bar id="my-component-id" bind="my-bind">
<xf:dispatch
event="fr-data-save-done"
observer="fr-form-model"
name="my-custom-event"
targetid="my-component-id"/>
</foo:bar>
The handler doesn't have to be within the element:
<foo:bar id="my-component-id" bind="my-bind"/>
<xf:dispatch
event="fr-data-save-done"
observer="fr-form-model"
name="my-custom-event"
targetid="my-component-id"/>
And inside the XBL component:
<xbl:binding id="my-binding-id" element="foo:bar">
<xbl:handlers>
<xbl:handler event="my-custom-event" phase="target">
... XForms actions here ...
</xbl:handler>
</xbl:handlers>
...
</xbl:binding>
I'm trying to implement a custom xbl component to submit the form to an external service, perform validation and handle the validation results. The version of orbeon is 4.4-CE deployed on JBoss 7.1.1.Final with MySQL persistence layer.
<xbl:binding element="fr|custom-submit" id="fr-custom-submit" xxbl:mode="lhha binding value">
<xbl:implementation>
<xf:model id="custom-submit-model">
<xf:instance id="validation-res">
<dummy/>
</xf:instance>
<!-- External validation submission -->
<xf:submission id="form-submission" ref="instance('fr-form-instance')"
action="http://localhost:8080/webapp/services/task/submitData" method="post"
replace="instance" instance="validation-res">
<xf:delete ev:event="xforms-submit" ref="//#v:*"/>
<xf:action ev:event="xforms-submit-done">
<!-- Insert external validation results when done -->
<xf:insert ref="." origin="instance('validation-res')/v:data/*"/>
<!-- Handle the valid/invalid result -->
</xf:action>
</xf:submission>
</xf:model>
</xbl:implementation>
<xbl:template>
<fr:button ref="xxf:binding('fr-custom-submit')">
<xf:label>
<xh:img src="/apps/fr/style/images/silk/disk.png"/>
<xh:span>Custom save</xh:span>
</xf:label>
<xf:send ev:event="DOMActivate" submission="form-submission"/>
</fr:button>
</xbl:template>
</xbl:binding>
Upon submitting the form the following exception occurs in the log files:
Empty single-node binding on xf:submission for submission id: form-submission |
I cannot figure out, what the exception means and if the cause of the problem is the strong encapsulation as described here.
Is it in general possible to write a custom xbl component for submitting a form? How can I overcome the above mentioned problem?
Regards
It is indeed an issue related to encapsulation, and using xxf:instance() allows you to break the encapsulation. So in your case, the submission would do:
ref="xxf:instance('fr-form-instance')"
Is there any XForms object which I could use to override default evaluation context inside an action object? We have xforms:group in body part but do we have any in xforms:action? It would simplify code where I often use the same Nodeset as a base element I'm operating on
I would like to receive such code:
<xf:action ev:event="DOMActivate">
<?xf:context? ref="instance('main')/d:Content/d:Attachment[index('repeat-id')]"> <!-- ?? -->
<xf:setvalue ref="d:FileName" value="..." />
<xf:setvalue ref="d:Description" value="..." />
<xf:setvalue ref="d:MimeType" value="..." />
<xf:setvalue ref="d:Size" value="..." />
<xf:setvalue ref="d:Location" value="..." />
</?xf:context?>
</xf:action>
so I wouldn't have to repeat the whole path all over again.
The attribute you are looking for is context. As of XForms 1.1, the context attribute is only available officially on the insert and delete actions, but some implementations already support it on all actions, and it is scheduled for inclusion in XForms 2.
<xf:action ev:event="DOMActivate" context="instance('main')/d:Content/d:Attachment[index('repeat-id')]">
<xf:setvalue ref="d:FileName" value="..." />
<xf:setvalue ref="d:Description" value="..." />
<xf:setvalue ref="d:MimeType" value="..." />
<xf:setvalue ref="d:Size" value="..." />
<xf:setvalue ref="d:Location" value="..." />
</xf:action>
Note that ref is, as far as I know, not officially allowed on action.
There is a difference between ref and context as planned for the upcoming XForms 2:
context only changes the XPath evaluation context
ref usually has other effects, such as binding a control, or specifying the destination of a value (setvalue), etc.
In XForms 1.1, context on insert unfortunately also can indicate the insertion point, but XForms 2 plans to improve on that and deprecate that use of context.
Yes. you can have ref attribute to the <xforms:action>tag. And you can apply this to <xforms:trigger> and <xforms:group> tags also.
With this, you will give the context for the statements within the tag.
I have tried this which works fine.
So your code should look something like:
<xf:action ev:event="DOMActivate" ref="instance('main')/d:Content/d:Attachment[index('repeat-id')]">
<xf:setvalue ref="d:FileName" value="..." />
<xf:setvalue ref="d:Description" value="..." />
<xf:setvalue ref="d:MimeType" value="..." />
<xf:setvalue ref="d:Size" value="..." />
<xf:setvalue ref="d:Location" value="..." />
</?xf:context?>
</xf:action>