updating a form value based on a different value in the form

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

updating a form value based on a different value in the form

marckropholler
Dear all,

Does anybody now how to automatically change form values depending on the values of other form values?
I've got two checkboxes (pointing to clearCapitalFlow and paymentObligations in the model) and a group
of radio buttons pointing to negativeFeatures in the model. Depending on the values of clearCapitalFlow
and paymentObligations, I would like to automatically set negativeFeatures. Does anybody now how to do
this? I've tried to add a xforms:trigger to the input tags, or directly adding xforms:setvalue, but I
didn't manage to get something working. Below is a fragment of view.xhtml.

Best wishes,
Marc


<xforms:input ref="instance('ws-request')/soap:Body/ws:ResolveIP/ws:clearCapitalFlow">
</xforms:input>

<xforms:input ref="instance('ws-request')/soap:Body/ws:ResolveIP/ws:paymentObligations">
</xforms:input>

<xforms:select1 ref="instance('ws-request')/soap:Body/ws:ResolveIP/ws:negativeFeatures" appearance="full">
        <xforms:item>
                <xforms:label>True</xforms:label>
                <xforms:value>true</xforms:value>
        </xforms:item>
        <xforms:item>
                <xforms:label>False</xforms:label>
                <xforms:value>false</xforms:value>
        </xforms:item>
</xforms:select1>
Reply | Threaded
Open this post in threaded view
|

Re: updating a form value based on a different value in the form

fl.schmitt(ops-users)
Hi Marc,

> I've tried to add a xforms:trigger to the input tags,

this shouldn't work because xforms:trigger creates a separate xforms
control - in your case, you already do have controls (the xforms:input);
and i think it isn't possible to nest those core controls.

But the following should work:

> or directly adding xforms:setvalue, but I
> didn't manage to get something working.

you're on the right way using xforms:setvalue. But it's hard to say
*why* it didn't work - there are a lot of possible reasons for problems
(wrong ev:event, wrong Xpath for the setvalue instruction are my
"favourite" ones ;) ).


Another approach would be to put the application logic ("set node a to
value x when node b got value y") into the XForms model. This way, you
don't have to modify the UI; instead, put a xforms:bind
nodeset="instance('ws-request')/soap:Body/ws:ResolveIP/ws:negativeFeatures"
calculate="..." into the model. I would prefer this solution if "node a"
shouldn't be modified manually at all - in your case: if the
negativeFeature shouldn't be modified by the user but only should get
changed depending on clearCapitalFlow and paymentObligations.

In your example, you had some xforms controls for negativeFeature, so i
assume that the user should be able to modify it directly. If this is
correct, i would prefer the xforms:action/xforms:setvalue way as a solution.

HTH
florian


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: updating a form value based on a different value in the form

marckropholler
Dear Florian,

Thank you for your help, we've used the <xforms:bind ... calculate="..:" /> you suggested and it works well.
Below is the code, copying and pasting it in a .xhtml file should be a working example.

Best wishes Marc

<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
            xmlns:xforms="http://www.w3.org/2002/xforms"
            xmlns:ev="http://www.w3.org/2001/xml-events"
            xmlns:xi="http://www.w3.org/2001/XInclude"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
                        xmlns:ws="http://ws.cdyne.com/">

    <xhtml:head>
        <xhtml:title>XForms Wizard - Step 1</xhtml:title>
        <xforms:model>
                        <xforms:instance id="ws-request">
                                <form>
                                        <action />
                                        <webservice>
                                                <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                                                        <soap:Header />
                                                        <soap:Body>
                                                                <ws:ResolveIP xmlns:ws="http://ws.cdyne.com/">
                                                                        <ws:clearCapitalFlow>false</ws:clearCapitalFlow>
                                                                        <ws:paymentObligations>false</ws:paymentObligations>
                                                                        <ws:negativeFeatures>false</ws:negativeFeatures>
                                                                </ws:ResolveIP>
                                                        </soap:Body>
                                                </soap:Envelope>
                                        </webservice>
                                </form>
                        </xforms:instance>
                       
                        <xforms:bind ref="instance('ws-request')/webservice/soap:Envelope/soap:Body/ws:ResolveIP/ws:clearCapitalFlow" type="xs:boolean"/>
                        <xforms:bind ref="instance('ws-request')/webservice/soap:Envelope/soap:Body/ws:ResolveIP/ws:paymentObligations" type="xs:boolean"/>
                        <xforms:bind ref="instance('ws-request')/webservice/soap:Envelope/soap:Body/ws:ResolveIP/ws:negativeFeatures"
                                        calculate="if ( (instance('ws-request')/webservice/soap:Envelope/soap:Body/ws:ResolveIP/ws:clearCapitalFlow = 'true') and
                                                        (instance('ws-request')/webservice/soap:Envelope/soap:Body/ws:ResolveIP/ws:paymentObligations = 'false') )
                                          then 'true' else 'false'" />

        </xforms:model>
    </xhtml:head>
   
    <xhtml:body>
        <xhtml:table cellpadding="2">

            <xhtml:tr>
                                <xhtml:td>Clear capital flow</xhtml:td>
                                <xhtml:td>
                                    <xforms:input ref="instance('ws-request')/webservice/soap:Envelope/soap:Body/ws:ResolveIP/ws:clearCapitalFlow">
                                    </xforms:input>
                                </xhtml:td>
                </xhtml:tr>

            <xhtml:tr>
                                <xhtml:td>Payment obligations</xhtml:td>
                                <xhtml:td>
                                    <xforms:input ref="instance('ws-request')/webservice/soap:Envelope/soap:Body/ws:ResolveIP/ws:paymentObligations">
                                    </xforms:input>
                                </xhtml:td>
                </xhtml:tr>

            <xhtml:tr>
                                <xhtml:td>Negative features present:</xhtml:td>
                                <xhtml:td>
                            <xforms:output ref="instance('ws-request')/webservice/soap:Envelope/soap:Body/ws:ResolveIP/ws:negativeFeatures" />
                                </xhtml:td>
                </xhtml:tr>

        </xhtml:table>
       
    </xhtml:body>
</xhtml:html>