Note that there are some explanatory texts on larger screens.

plurals
  1. POXForms and multiple inputs for same model tag
    primarykey
    data
    text
    <p>I apologize ahead of time if I am not asking this properly.. it is hard to put into words what I am asking..</p> <p>I have XForms model such as:</p> <pre><code>&lt;file&gt; &lt;criteria&gt; &lt;criterion&gt;&lt;/criterion&gt; &lt;/criteria&gt; &lt;/file&gt; </code></pre> <p>I want to have multiple input text boxes that create a new criterion tag.</p> <p>user interface such as:</p> <pre><code>&lt;xf:input ref="/file/criteria/criterion" model="select_data"&gt; &lt;xf:label&gt;Select&lt;/xf:label&gt; &lt;/xf:input&gt; &lt;xf:input ref="/file/criteria/criterion" model="select_data"&gt; &lt;xf:label&gt;Select&lt;/xf:label&gt; &lt;/xf:input&gt; &lt;xf:input ref="/file/criteria/criterion" model="select_data"&gt; &lt;xf:label&gt;Select&lt;/xf:label&gt; &lt;/xf:input&gt; </code></pre> <p>And I would like the XML output to look like this (once user has entered in info):</p> <pre><code>&lt;file&gt; &lt;criteria&gt; &lt;criterion&gt;AAA&lt;/criterion&gt; &lt;criterion&gt;BBB&lt;/criterion&gt; &lt;criterion&gt;CCC&lt;/criterion&gt; &lt;/criteria&gt; &lt;/file&gt; </code></pre> <p>The way I have it doesn't work, as it sees the 3 input fields to be referring all to the same criterion tag. How do I differentiate?</p> <p>Thanks! I hope that made some sense!</p> <p><strong>BEGIN FIRST EDIT</strong></p> <p>Thanks for the responses for the basic text box!</p> <p>However, I now need to do this with a listbox. But for the life of me, I can't figure out how. I read somewhere to use with the xforms:select and deselect events.. but I didn't know where to place them, and the places I tried gave me very weird behaviour.</p> <p>I am currently implementing the following: </p> <pre><code>&lt;xf:select ref="instance('criteria_data')/criteria/criterion" selection="" appearance="compact" &gt; &lt;xf:label&gt;Choose criteria&lt;/xf:label&gt; &lt;xf:itemset nodeset="instance('criteria_choices')/choice"&gt; &lt;xf:label ref="@label"&gt;&lt;/xf:label&gt; &lt;xf:value ref="."&gt;&lt;/xf:value&gt; &lt;/xf:itemset&gt; &lt;/xf:select&gt; </code></pre> <p><em>However</em> when multiple choices are submitted, all selection values are inserted into the same node, separated by spaces.</p> <p>For example:</p> <p>If AAA and BBB and FFF were selected from listbox, it would result in the following XML:</p> <pre><code>&lt;criterion&gt;AAA BBB FFF&lt;/criterion&gt; </code></pre> <p>How do I change my code to have each selection be in a separate node?</p> <p>i.e. I want it to look like this:</p> <pre><code>&lt;criterion&gt;AAA&lt;/criterion&gt; &lt;criterion&gt;BBB&lt;/criterion&gt; &lt;criterion&gt;FFF&lt;/criterion&gt; </code></pre> <p>Thanks!</p> <p><strong>END FIRST EDIT</strong></p> <p><strong>BEGIN SECOND EDIT:</strong></p> <p>For the listboxes (ie xf:select appearance="compact") I ended up allowing the spaces to occur in the same node and then just transformed that xml using xsl to generate a properly formatted new xml doc (with separate individual nodes). Unfortunately, I did not find a less cumbersome solution by inserting them originally into separate nodes.</p> <p>The selected answer works very well for text boxes however, hence why I selected it as the answer.</p> <p><strong>END SECOND EDIT</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload