xforms:submit event is raised before the submission happens and any changes to node values before submission can be achieved.
I have tried doing this, i could see the value is getting changed on the browser, but the saved node still have the old data. Any idea on this.
<xforms:submission id="save-instance" ref="instance('form-instance')"
action="{instance('temp-instance')/submit-url}" method="post" validate="false" replace="none">
<xforms:action ev:observer="save-instance" ev:event="xforms-submit">
<xforms:message level="modal" value="'About to Submit'" />
<xxforms:script>
ORBEON.xforms.Document.setValue("location-of-dda-id-a", 'Test3');
</xxforms:script>
</xforms:action>
<xforms:action ev:observer="save-instance" ev:event="xforms-submit-done">
<xforms:message level="modal" ref="instance('metaData')/save-success-msg" />
</xforms:action>
<xforms:message ev:event="xforms-submit-error" level="modal" ref="instance('metaData')/save-error-msg" />
</xforms:submission>
And the id location-of-dda-id-a
is the id given for an input field.
Basically, i wanted to replace the special characters that are copied and pasted from MS documents. Below is the Js function that can achieve this.
var specialChars = [/\u0011/g, /\u0012/g, /\u0013/g, /\u0014/g, /\u0016/g, /\u2018/g, /\u2019/g, /\u201c/g, /\u201d/g, /\u2026/g, /\u2013/g, /\u2219/g, /\u2022/g,/\u00BF/g];
var specialCharsReplacement = ["", "", "", "", "", "'", "'", "\"", "\"", "...","-","-","-","?"];
function replaceSpecialChars(formName)
{
for(i = 0; i < formName.elements.length; i++)
{
if (formName.elements[i].type == 'textarea' || formName.elements[i].type=='text')
{
var commentText = formName.elements[i].value;
if(commentText != 0)
{
for(j = 0; j < specialChars.length; j++)
{
commentText = commentText.replace(specialChars[j], specialCharsReplacement[j]);
}
formName.elements[i].value = commentText;
}
}
}
}
And the line
formName.elements[i].value = commentText;
should be replaced with
ORBEON.xforms.Document.setValue(formName.elements[i].id.split("\$")[0], commentText);
But it is not working.