views:

43

answers:

1

Hi!

I am changing my code to use binds in XForms (which is better practice than using nodesets everywhere!) but I am getting errors.

The error message I receive is: "Error: XForms Error (8): id (data_criterion) does not refer to a bind element..."

From tutorials/guides I have been using, it seems as though this should work, but clearly I am missing something! (btw, I was modeling my binding code after the examples here: http://en.wikibooks.org/wiki/XForms/Bind)

I originally thought the problem was due to the fact I was using xf:select controls as opposed to xf:input like the examples, but even once I dumbed down my code to the most simplistic code, I still receive errors!

This is the model code I am using:

 <xf:model id="select_data">

     <xf:instance id="criteria_data" xmlns="">
         <file>
             <criteria>
                 <criterion></criterion>
             </criteria>
         </file>
     </xf:instance>

     <bind id="data_criterion" nodeset="instance('criteria_data')/criteria/criterion"/>

</xf:model>

As for the ui code, this is what I have:

<xf:input bind="data_criterion">
    <xf:label>Enter criteria:</xf:label>
</xf:input>

The error message I receive is: "Error: XForms Error (8): id (data_criterion) does not refer to a bind element..."

Anyone have any insight to what the problem is? Also, is there any special usage of bindings and xf:select (with xf:itemset) controls that I should be aware of? (I am ultimately using a lot of xf:select controls on my form..)

Thanks in advance!

EDIT:

I ran the code through this validator, and I got this message (refers to the bind line): "Warning: Should the following element have the XForms namespace applied?: bind (line 66)"

+2  A: 

A couple of things you might want to change:

  1. Not sure of this is the reason for the error, but the nodeset expression should be instance('criteria_data')/criteria/..., without file. Remember: instance() returns the root element, not the document node. (This one you took care by updating the question; good)
  2. You are missing the xf on the bind. It should be: <xf:bind id="data_criterion" nodeset="instance('criteria_data')/criteria/criterion"/>.

See below a full example with your code, which works fine for me under Orbeon Forms:

<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
      xmlns:xforms="http://www.w3.org/2002/xforms"
      xmlns:xf="http://www.w3.org/2002/xforms"
      xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:fr="http://orbeon.org/oxf/xml/form-runner"&gt;
    <xhtml:head>
        <xhtml:title>SO Bind</xhtml:title>
        <xf:model id="select_data">

            <xf:instance id="criteria_data" xmlns="">
                <file>
                    <criteria>
                        <criterion>Gaga</criterion>
                    </criteria>
                </file>
            </xf:instance>
            <xf:bind id="data_criterion" nodeset="instance('criteria_data')/criteria/criterion"/>
       </xf:model>

    </xhtml:head>
    <xhtml:body>
        <xf:input bind="data_criterion">
            <xf:label>Enter criteria:</xf:label>
        </xf:input>
    </xhtml:body>
</xhtml:html>
Alessandro Vernet
hmm... this is a good point, and an oversight on my part. But I still have the error.. :( I will edit my code in my question to reflect this though. Thanks for replying! :)
developer
@iHeartGreek, there is also a missing prefix on the `bind`. See #2 above, and my edited response.
Alessandro Vernet
OMG. thanks. that's all it was.. :( I feel incredibly stupid now. Thanks for the extra eyes. I will try to be more careful now. I want to delete this question because I am embarrassed, but I won't because you deserve the points for answering! :)
developer
@iHeartGreek, I am glad it helped. Extra eyes are sometimes all we need. I know how it is :).
Alessandro Vernet