W3C home > Mailing lists > Public > www-forms@w3.org > August 2006

RE: Can toggle@case or case@selected be calculated?

From: Kugelman, John <jkugelman@progeny.net>
Date: Thu, 10 Aug 2006 11:08:04 -0400
Message-ID: <9A0E40933DE3E548A1B8E32063CE4EE482B508@es3.progeny.net>
To: <mark.birbeck@x-port.net>, "Flinton Adam" <Adam.Flinton@cfh.nhs.uk>
Cc: <www-forms@w3.org>

Has the working group ever considered allowing the active case to be
calculated declaratively, like relevance? I can imagine something like:

    <switch select="concat('case-', x)">
      <case id="case-1"/>
      <case id="case-1"/>
      <case id="case-1"/>
    </switch>

Or

    <switch>
      <case selected="x = 1"/>
      <case selected="x = 2"/>
      <case selected="x = 3"/>
    </switch>

Or even

    <switch value="x">
      <case when="1"/>
      <case when="2"/>
      <case when="3"/>
    </switch>

It would be nice to have UI-level declarative control over visibility
without having to create or modify instance data.

Or, more generally, how about being able to put @relevant directly on
controls? Quite often (dare I say, almost always) relevance is used to
control the UI and not to determine what instance data is submitted. I
would love to be able to show/hide a group without having to add a
binding to the model, and then deal with part of the instance data not
being submitted.

John

-----Original Message-----
From: www-forms-request@w3.org [mailto:www-forms-request@w3.org] On
Behalf Of Mark Birbeck
Sent: Thursday, August 10, 2006 9:00 AM
To: Flinton Adam
Cc: www-forms@w3.org
Subject: Re: Can toggle@case or case@selected be calculated?


Hi Adam,

Using @relevant is pretty much the way to do it. However, you will
need an extra instance to do this, since as you say, the data is the
same in both branches. switch/case is much more about a 'UI state'
that is not reflected in the model--rather like the position of a
scroll bar. If you want to actually reflect *model* state back into
the form then use @relevant.

So, to set it up, create two groups, bound to something like
"instance('i-control')/input" and "instance('i-control')/output". The
instance data would look something like this:

  <controls @state="input">
    <input />
    <output />
  </controls>

Then set up some bind statements so that these nodes are relevant
based on some rules, e.g.:

  <bind nodeset=""instance('i-control')">
    <bind id="ns-state" nodeset="@state" />
    <bind nodeset="input" relevant="../@state = 'input'" />
    <bind nodeset="output" relevant="../@state = 'output'" />
  </bind>

Now all you have to do to swap between the two (or how ever many you
like) groups is to set the value of $ns-state. This can be done either
by directly setting it, perhaps with a trigger (you might format the
triggers like tabs):

  <setvalue ev:action="toggle-input" bind="ns-state">input</setvalue>
  <setvalue ev:action="toggle-output" bind="ns-state">output</setvalue>

In your case you would use a bind calculation to set @state based on
your data.

Once you've set the value everything else is done for you.

We use this technique a lot, to create complex, nested, tabbed dialogs.

All the best,

Mark


On 10/08/06, Flinton Adam <Adam.Flinton@cfh.nhs.uk> wrote:
>
> Dear All,
>
> I am trying to switch a form between being made up of a group of
output
> elements & a group of input elements, dependant upoon a value
contained
> in an instance which says if the data is readonly or not. The Value is
> carried in an element called OID_key & if it is 0 then it is readonly
&
> if 1 then it is read/write.
>
> Basically what I want to say is "If OID_key = 0 then use the NoEdit
Case
> & thus group of controls & if 1 then use the Edit case/group of
> controls"
>
>
> I have tried using a calculated value for both toggle@case and
> case@selected to no effect. See below for the 2 examples where the
> commented out part is the attempt at getting a calculated value.
>
>
> <xforms:toggle ev:event="xforms-ready" case="Edit"/>
> <!--<xforms:toggle ev:event="xforms-ready" case="if(OID_key =
> 0,NoEdit,Edit)"/>  -->
>
>
> <xforms:switch>
> <xforms:case id="Edit" selected="true">
> <!-- <xforms:case id="Edit" selected="if(OID_key = 0,false(),true())">
> -->
>
>
> Given I wish to keep the instance & simply display the information
> differently, the "relevant=" model switching is not of use so.....if
> there any way I can get an Xpath/function based value into either
> toggle@case or case@selected?
>
> Adam
>
>
>
> This e-mail is confidential and privileged. If you are not the
intended recipient please accept our apologies; please do not disclose,
copy or distribute information in this e-mail or take any action in
reliance on its contents: to do so is strictly prohibited and may be
unlawful. Please inform us that this message has gone astray before
deleting it. Thank you for your co-operation.
>
>
>
>
>


-- 
Mark Birbeck
CEO
x-port.net Ltd.

e: Mark.Birbeck@x-port.net
t: +44 (0) 20 7689 9232
w: http://www.formsPlayer.com/
b: http://internet-apps.blogspot.com/

Download our XForms processor from
http://www.formsPlayer.com/
Received on Thursday, 10 August 2006 15:08:24 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 10 March 2012 06:22:06 GMT