How to use <xf:setvalue> to update a javascript-restructured model?

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

How to use <xf:setvalue> to update a javascript-restructured model?

ankostis
Hi,

I cannot successfully restructure a model-node through Javascript and
then use <xf:setvalue> to update its content but i cannot!

* Is it BUG again: https://bugzilla.mozilla.org/show_bug.cgi?id=356879
* How can i workaround it?

For example, i'm using JS to add a <proci:procinfos> element into
<data:root>.
This example is a striped-down version
Here is a sample code (ready to be cut'n pasted):

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:proci="http://services.forthnet.gr/xml/ns/procinfos"
    xmlns:data="http://services.forthnet.gr/xml/ns/rexser/2play"
    xmlns:ev="http://www.w3.org/2001/xml-events"
    xmlns:xf="http://www.w3.org/2002/xforms"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation=
    "http://www.w3.org/2002/xforms http://www.w3.org/MarkUp/Forms/2002/XForms-Schema.xsd">

<head>

<script type="text/javascript">
function appendNode(
        model, instance) {
    var model = document.getElementById(model);
    var instance = model.getInstanceDocument(instance);

    newNode = instance.createElement('proci:node');
    var rootNode = instance.documentElement;
    rootNode.appendChild(newNode);

    model.rebuild();
    model.recalculate();
    model.revalidate();
    model.refresh();
}
</script>


<xf:model id="main-model" >

    <xf:instance id="request-instance" >
        <data:root>
            <!--  JS WIL ADD <proci:node> HERE  -->
        </data:root>
    </xf:instance>

    <xf:submission id="save-to-local-file" method="put"
action="data.xml">

        <xf:action ev:event="xforms-submit">

            <!-- 1) JS inserts a new <proci:procInfo> section. OK -->
            <xf:load
                       resource="javascript:appendNode(
                   'main-model', 'request-instance')" />

            <!-- 2) Attempt to modify JS-created element. -->
                                                <!-- DOES NOT WORK! IS IT BUG: https://bugzilla.mozilla.org/show_bug.cgi?id=349805
-->
            <xf:setvalue ev:event="xforms-submit"
                ref="proci:node"
                value="'HALLO'"/>
        </xf:action>

    </xf:submission>
</xf:model>

</head>

<body>
    <xf:trigger>
        <xf:label>Submit</xf:label>
        <xf:send ev:event="DOMActivate" submission="save-to-local-
file" />
    </xf:trigger>
</body>
</html>


Thank you in advance,
  Kostis

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

RE: How to use <xf:setvalue> to update a javascript-restructured model?

Clark, John
Kostis,

> I cannot successfully restructure a model-node through
> Javascript and then use <xf:setvalue> to update its content
> but i cannot!

> For example, i'm using JS to add a <proci:procinfos> element
> into <data:root>.
> This example is a striped-down version
> Here is a sample code (ready to be cut'n pasted):

>     newNode = instance.createElement('proci:node');

This is the problem.  When you insert an element like this, you are
doing it in a namespace-unaware manner, so that your later reference to
the element using a QName fails (in the setvalue).  Replacing the above
line with this call, which is namespace-aware, works:

      newNode =
instance.createElementNS("http://services.forthnet.gr/xml/ns/procinfos",
'proci:node');

I'm actually surprised that your original example worked at all; I don't
know how the DOM interprets a QName with no namespace being inserted
into a namespace-aware document that has a namespace associated with
that prefix.  I recommend sticking with the *NS DOM variants.  :)

Take care,

    John L. Clark

===================================

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News & World Report (2007).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use
only by the individual or entity to which it is addressed
and may contain information that is privileged,
confidential, and exempt from disclosure under applicable
law.  If the reader of this message is not the intended
recipient or the employee or agent responsible for
delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If
you have received this communication in error,  please
contact the sender immediately and destroy the material in
its entirety, whether electronic or hard copy.  Thank you.



_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: How to use <xf:setvalue> to update a javascript-restructured model?

ankostis
In reply to this post by ankostis
On Aug 28, 11:12 pm, "Clark, John" <[hidden email]> wrote:

> Kostis,
>
> > I cannot successfully restructure a model-node through
> > Javascript and then use <xf:setvalue> to update its content
> > but i cannot!
> > For example, i'm using JS to add a <proci:procinfos> element
> > into <data:root>.
> > This example is a striped-down version
> > Here is a sample code (ready to be cut'n pasted):
> >     newNode = instance.createElement('proci:node');
>
> This is the problem.  When you insert an element like this, you are
> doing it in a namespace-unaware manner, so that your later reference to
> the element using a QName fails (in the setvalue).  Replacing the above
> line with this call, which is namespace-aware, works:
>
>       newNode =
> instance.createElementNS("http://services.forthnet.gr/xml/ns/procinfos",
> 'proci:node');
>
> I'm actually surprised that your original example worked at all; I don't
> know how the DOM interprets a QName with no namespace being inserted
> into a namespace-aware document that has a namespace associated with
> that prefix.  I recommend sticking with the *NS DOM variants.  :)

Correct!
Indeed, I mistakenly believed that all was OK with the non-NS-aware
version, since the resulting XML was identical.

Thank you, Clark

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms