1

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.

4

1 回答 1

3

这是一个棘手的问题:您可以正确地说xforms-submit操作在提交完成之前运行,但这发生在服务器上,并且在服务器xxforms:script上执行其他所有操作之后运行在浏览器上。所以在使用的时候需要注意一些xxforms:script

在这种情况下,最好使用 anxforms:setvalue而不是xxforms:script设置值。(一般来说,最好离开xxforms:scriptXForms 中无法完成的事情。)

于 2012-12-19T18:30:02.980 回答