Save/Auto-Save Action Events

7 views
Skip to first unread message

Joel Oates

unread,
Aug 15, 2019, 3:50:51 AM8/15/19
to orb...@googlegroups.com
Hello !

In one of your form we have an instance that holds a Boolean value, we base
all high level bindings (except that of the control that handles the Boolean
value) of the form off that value. for example:


<xf:instance id="isCompleteInstance">
<isComplete/>
</xf:instance>

<xf:bind ref="instance('fr-form-instance')/discharge-plan-gp"
readonly="instance('isCompleteInstance') = 'true'/>

Now I have a check box the enables and disables the read only part of the
binding with the following select (check box) control

<xf:select appearance="full"
id="isComplete-control"
ref="instance('isCompleteInstance')">
<xf:label ref=""/>
<xf:hint ref="/>
<xf:help ref=""/>
<xf:alert ref=""/>
<xf:itemset nodeset="$form-resources/control-76/item">
<xf:label ref="label"/>
<xf:value ref="value"/>
</xf:itemset>
<xf:action ev:event="xforms-value-changed">
<xf:setvalue if=".='false true'" ref="." value="'true'"/>
</xf:action>
</xf:select>

this all works fine. So once you tick the check box the whole form (except
the check box) becomes read only. Now once we submit the form we want to
copy the value of the "isCompleteInstance" instance to the form data. We are
doing this by doing the following action.

<xf:setvalue ev:event="fr-data-save-prepare"
ref="instance('fr-form-instance')/isComplete"
value="instance('isCompleteInstance')"/>

Now, when the form loads we want to copy the value in the form to the
instance so it remains read-only, we do this with

<xf:setvalue ev:event="xforms-ready"
ref="instance('isCompleteInstance')"
value="instance('fr-form-instance')/isComplete"/>


All of this works fine! We have a check box that we can select when to make
the form read only, when we are creating it, but we can deselect it if we
make a mistake and can change it before saving the form, once saved with the
check box selected, the form can never be edited again.

Works great!

However, there is an issue with the event /fr-data-save-prepare/ event with
auto save. Say we select the check box the makes out form read only, and an
auto save happens. The /fr-data-save-prepare/ is triggered! which causes the
check box to go read-only! Which is not the desired out-come, as the person
my not be finished with the form even when the check box was selected!

Is there any event that I can use that is only triggered when the save
button is pressed but after the validation has been passed? Also not
triggered on auto save events..


Thanks for your time!

Any issues with my explanation let me know!

Joel.

--
Sent from: http://discuss.orbeon.com/

Alessandro Vernet

unread,
Aug 15, 2019, 11:57:54 AM8/15/19
to orb...@googlegroups.com
Hi Joel,

Instead of relying on XForms code that runs on `fr-data-save-prepare` to
copy the value of `instance('isCompleteInstance')` to
`instance('fr-form-instance')/isComplete`, I'd recommend you do this in the
"save" process. For instance, if you are using the `save-final` button, that
process is currently defined as follows (you might want to check exactly how
it is defined in the version of Orbeon Forms you are using, looking at the
`properties-form-runner.xml`):

<property as="xs:string" name="oxf.fr.detail.process.save-final.*.*">
require-uploads
then validate-all
then save
then new-to-edit
then success-message("save-success")
recover error-message("database-error")
</property>

Between the `then validate-all` and the `then save`, that is after the data
has been validated, but before it is saved, you can insert a:

then xf:setvalue(
ref = "/form/isComplete",
value = "instance('isCompleteInstance')"
)

You'll let me know if this works for you.

‑Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet

Joel Oates

unread,
Aug 21, 2019, 9:16:53 PM8/21/19
to orb...@googlegroups.com
Hi Alex,

Thanks for the reply.

That works for my current form, however that will run on every form that is
saved, I would consider putting this property in the form (I don't know if
you can do that, or even if it works) however As we already have a modified
save-final property I wouldn't want to copy that code to the form as well.

So follow up question, is it possible to trigger a custom event instead?
Using the following java script from the documentation:

ORBEON.xforms.Document.dispatchEvent(
{
targetId: 'my-target',
eventName: 'my-event'
}
);

and then call the event in the save-final property? If so what would this
look like?

Cheers,
Joel.

Alessandro Vernet

unread,
Aug 22, 2019, 1:13:09 PM8/22/19
to orb...@googlegroups.com
Hi Joel,

Are you saying that you'd like this particular behavior on save to only
happen for a specific form? If so, instead of setting the property
`oxf.fr.detail.process.save-final.*.*`, use the property name
`oxf.fr.detail.process.save-final.MYAPP.MYFORM`, replacing MYAPP and MYFORM
with your specific app/form name. Would that work for you?

‑Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet

Alessandro Vernet

unread,
Aug 29, 2019, 1:06:35 PM8/29/19
to orb...@googlegroups.com
Hi Joel, did you get a chance to try using the suggested property name? If
so, did that work for you?

Joel Oates

unread,
Sep 9, 2019, 10:18:27 AM9/9/19
to orb...@googlegroups.com
Hey Alex, Sorry for late reply (Emails were notifications were not getting
through )

I did try that fix locally which did work, how ever it is not very
desirable, as there could be more forms made in the future with the same
functionality.

I have parked the issue at the moment, but need to find a solution..

Is it possible to create a custom event and trigger it only on the save?
Just like you were suggesting with the set value, but instead dispatching a
"my-event"?

Thanks Again,
Joel.

Alessandro Vernet

unread,
Sep 10, 2019, 12:39:15 PM9/10/19
to orb...@googlegroups.com
Hi Joel,

I am not sure what you mean by: "I did try that fix locally which did work,
how ever it is not very desirable, as there could be more forms made in the
future with the same functionality." If you use an `xf:setvalue()` in a
process, since the process is defined in a property, you can have the
process apply to multiple forms, using wildcards in the property name. How
would having this functionality written in XForms make it easier to apply to
multiple forms?

‑Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply all
Reply to author
Forward
0 new messages