Quantcast

XForms Optional Field Submit instance - Possible?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

XForms Optional Field Submit instance - Possible?

Vedha
I like to know whether it is possible to skip any specific element(based on some condition) when we submit the instance.

For example,

            <xf:instance id="samples">
            <info xmlns="">
           
           
            </info>
            </xf:instance>
           
             <xf:submission id="submit"
            ref="instance('samples')"
            resource="url"
            method="post"
            validate="false"
            mediatype="application/xml"
            replace="instance" instance="serverResponse" >
  </xf:submission>
 
 
        </xf:model>
    </xh:head>
    <xh:body>
   
<xf:input ref="instance('samples')/a"></xf:input>
<xf:input ref="instance('samples')/b"></xf:input>

    </xh:body>

In this small sample, there are two input fields mapped to two elements of instance. During submit, i like to skip element 'a' or 'b' based on their empty status. I mean, if user did not enter any value in field 'a' then i do not want submit that element, submited instance should be like,

If a = "" - blank
b = "2"

            <xf:instance id="samples">
            <info xmlns="">
            2
            </info>
            </xf:instance>

Note:
1) element a is not available here.
2) I cannot use relevant here as i want to see the field in screen.

Is this feasible in Orbeon? Or is there a generic way to handle this?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: XForms Optional Field Submit instance - Possible?

Alessandro  Vernet
Administrator
This post was updated on .
(Updated to use aa instead of a, and bb instead b, so Nabble doesn't think I want to have something in bold.)

Hi Vedha,

I am just trying to understand your requirement here: your "samples" instance will most likely look like <info><aa/><bb/></info>, but you're saying that if <aa> is empty and <bb> is 2, you want <info>2</info> to be submitted. What about if <aa/> and <bb/> are non-empty? Or that wouldn't be possible for that form?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: XForms Optional Field Submit instance - Possible?

Alessandro  Vernet
Administrator
(Reposting my answer, using aa instead of a, and bb instead b, so Nabble doesn't think I want to have something in bold.)

Hi Vedha,

I am just trying to understand your requirement here: your "samples" instance will most likely look like <info><aa/><bb/></info>, but you're saying that if <aa> is empty and <bb> is 2, you want <info>2</info> to be submitted. What about if <aa/> and <bb/> are non-empty? Or that wouldn't be possible for that form?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: XForms Optional Field Submit instance - Possible?

Vedha
This post was updated on .
Thanks for your response. Below are the cases,

if aa = '2', bb = '', then submit should be,

<xf:instance id="samples">
            <info xmlns="">
            <aa>2</aa>
            </info>
            </xf:instance>

if aa = '2', bb = '22', then submit should be,

<xf:instance id="samples">
            <info xmlns="">
            <aa>2</aa>
            <bb>22</bb>
            </info>
            </xf:instance>

if aa = '', bb = '', then submit should be,

<xf:instance id="samples">
            <info xmlns="">
            </info>
            </xf:instance>

In both the cases, both fields should be available on screen.


Note: My question does look conflict with data in my previous post question, this because of the b tag which i used. Now i am using aa and bb tag.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: XForms Optional Field Submit instance - Possible?

Alessandro  Vernet
Administrator
Hi Vedha,

Got it. To do this, you could leverage the <xf:submission> ability to prune non-relevant nodes from the XML when it sends the data:

- If you have own submission, use the relevant="true" attribute.
- If in the context of Form Runner, and you're triggering the submission from an process, use send(prune = "true").

In addition, you'll need to make those empty nodes non-relevant, and this only when the submission happens. You could do this by having an attribute set to true upon submission, with an xf:setvalue, say on <info submitting="true">…</info>, and then in the binds check on that attribute, e.g.:

<xf:bind ref="instance('samples')/(aa, bb)" relevant=". != '' or instance('samples')/submitting != 'true'"/>

And since you don't want the "submitting" attribute to be included, you could always make it non-relevant:

<xf:bind ref="instance('samples')/@submitting" relevant="false()"/>

Would something along those lines work for you?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: XForms Optional Field Submit instance - Possible?

Vedha
Got this. One more blind question, just curious.

Is there a way in Orbeon to display a particular field on screen when the ref XML node is not available?. And also, when user enter some value on that field, then we need to create that XML node.

For example,

Initial instance,


<instance id='sample'>
<SAMPLE>
</SAMPLE>
</instance>

Input field, I want to display this field, even though that ref mapped element (SUPER) is not available in Instance.

<xf:input ref="instance('sample')/SAMPLE/SUPER">

And when your input some values on this input field, then

That element should be created in instance (Not while submitting),

<instance id='sample'>
<SAMPLE>
<SUPER>User Value</SUPER>
</SAMPLE>
</instance>

I know we can have temp instance and achieve this functionality, my question would be, is there a generic way in Orbeon to handle scenarios like this Optional fields with ref node not present.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: XForms Optional Field Submit instance - Possible?

Alessandro  Vernet
Administrator
Hi Vedha,

Unfortunately not. When a ref expression returns an empty sequence, the control is considered to be non-relevant. So if you expect users to fill out a certain field, the corresponding node will need to exist in the XML.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: XForms Optional Field Submit instance - Possible?

Vedha
Thanks for your response. Helps a lot in understanding.
Loading...