Search code examples
orbeon

Can I check if the form is dirty in a custom process or with JavaScript?


I have a custom process tied to a button, defined as follows:

<property as="xs:string" name="oxf.fr.detail.process.send-to-myservice.*.*">
    set-data-status(status="safe")
    then send(
              uri="http://localhost:8080/myservice",
              content="xml",
              replace="none",
              prune="true"
             )
    then success-message(message="Save Successful")
    then navigate(uri="javascript:window.MY_NAMESPACE.orbeonPostSave()")
    recover error-message(message="Save Failed")
</property>
<property as="xs:string" name="oxf.fr.resource.*.*.en.buttons.send-to-myservice" value="Save"/>

I would like to perform the send operation only if the form is dirty. Can I change this process to conditionally send only if clean?

I am using the proxy portlet and actually hiding the Orbeon button. I have my own custom buttons that simulate clicking on the Orbeon button using JavaScript. Is there a JavaScript function I can call to check the data-status? That would be just as good or maybe better.


Solution

  • It looks like you're looking for the "opposite" of set-data-status(), i.e. something to read the data status. Right now, you would have to do this using XPath, with something like:

    if ("xxf:instance('fr-persistence-instance')/data-status = 'dirty'")
    then send(…)
    else nop
    

    And, obviously, you'd have to do this before you run set-data-status(status="safe"), otherwise the test will always fail.