Save/Auto-Save Action Events

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Save/Auto-Save Action Events

Joel Oates
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/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/1565855450838-0.post%40n4.nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Save/Auto-Save Action Events

Alessandro  Vernet
Administrator
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
--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/1565884673055-0.post%40n4.nabble.com.
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Save/Auto-Save Action Events

Joel Oates
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.

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

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/1566436611478-0.post%40n4.nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Save/Auto-Save Action Events

Alessandro  Vernet
Administrator
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
--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/1566493988904-0.post%40n4.nabble.com.
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Save/Auto-Save Action Events

Alessandro  Vernet
Administrator
Hi Joel, did you get a chance to try using the suggested property name? If
so, did that work for you?

‑Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/1567098393962-0.post%40n4.nabble.com.
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Save/Auto-Save Action Events

Joel Oates
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.

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

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/1568038705019-0.post%40n4.nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Save/Auto-Save Action Events

Alessandro  Vernet
Administrator
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
--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/orbeon/1568133553408-0.post%40n4.nabble.com.
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet