Dealing with optional attributes

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

Dealing with optional attributes

mjgraham
Hi,

I have an instance:

<xf:instance id="resource">
  <resource>
    <contributor ident=""/>
  </resource>
</xf:instance>

where the ident attribute is optional according to the schema. However,
if it takes a value then there is a pattern it must match so I add a bind:

<xf:bind nodeset="instance('resource')/contributor/@ident"
constraint="matches(., pattern)"/>

The control is then just:

<xf:input ref="instance('resource')/contributor/@ident"/>

Now if the user does not specify a value then the ident attribute takes
on the empty value which is illegal according to the schema since it
does not match the pattern so: <contributor ident=""/> is illegal but
<contributor /> is fine. But if I remove the ident attribute from the
instance then the control does not appear.

Is there any way of having a loose binding so that if a value is
specified, it has to agree with the constraint but if one is not
specified then the attribute is not submitted. There is nothing that it
can be made relevant on.

    Cheers,
     
    Matthew



--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Dealing with optional attributes

Hank Ratzesberger

Is it possible to use an <xf:trigger>, and not an <xf:submit>,
so that you can take an <xf:action> to <xf:setvalue> the
relevant attribute of your instance when (just before) it
is submitted?

And your submission would need to use the relevant="true",
the default, to prune the element out.

Just a guess,
Hank
UCSB

----- Original Message -----
From: "Matthew Graham" <[hidden email]>
To: <[hidden email]>
Sent: Tuesday, April 17, 2007 2:42 PM
Subject: [ops-users] Dealing with optional attributes


> Hi,
>
> I have an instance:
>
> <xf:instance id="resource">
>  <resource>
>    <contributor ident=""/>
>  </resource>
> </xf:instance>
>
> where the ident attribute is optional according to the schema. However,
> if it takes a value then there is a pattern it must match so I add a bind:
>
> <xf:bind nodeset="instance('resource')/contributor/@ident"
> constraint="matches(., pattern)"/>
>
> The control is then just:
>
> <xf:input ref="instance('resource')/contributor/@ident"/>
>
> Now if the user does not specify a value then the ident attribute takes
> on the empty value which is illegal according to the schema since it
> does not match the pattern so: <contributor ident=""/> is illegal but
> <contributor /> is fine. But if I remove the ident attribute from the
> instance then the control does not appear.
>
> Is there any way of having a loose binding so that if a value is
> specified, it has to agree with the constraint but if one is not
> specified then the attribute is not submitted. There is nothing that it
> can be made relevant on.
>
>    Cheers,
>    
>    Matthew
>
>

--------------------------------------------------------------------------------


>
> --
> 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
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
>



--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Dealing with optional attributes

Erik Bruchez
Administrator
In reply to this post by mjgraham
Matthew,

There is no concept of "lazy" binding of a control to a yet-to-exist
attribute in XForms.

For that kind of use case, you probably need to have a trigger (which
can display as a nice "+" icon) that allows inserting the attribute with
xforms:insert when it is missing. Once the attribute is visible, your
xforms:select1 will show and allow selecting a valid value of the attribute.

To remove the attribute, you can use a trigger as well ("-") that
removes the attribute with xforms:delete, or you can decide to
automatically remove the attribute when the user select a special value
in the xforms:select1.

This would be a nice little example to have ;-)

-Erik

Matthew Graham wrote:

> Hi,
>
> I have an instance:
>
> <xf:instance id="resource">
>  <resource>
>    <contributor ident=""/>
>  </resource>
> </xf:instance>
>
> where the ident attribute is optional according to the schema. However,
> if it takes a value then there is a pattern it must match so I add a bind:
>
> <xf:bind nodeset="instance('resource')/contributor/@ident"
> constraint="matches(., pattern)"/>
>
> The control is then just:
>
> <xf:input ref="instance('resource')/contributor/@ident"/>
>
> Now if the user does not specify a value then the ident attribute takes
> on the empty value which is illegal according to the schema since it
> does not match the pattern so: <contributor ident=""/> is illegal but
> <contributor /> is fine. But if I remove the ident attribute from the
> instance then the control does not appear.
>
> Is there any way of having a loose binding so that if a value is
> specified, it has to agree with the constraint but if one is not
> specified then the attribute is not submitted. There is nothing that it
> can be made relevant on.
>
>    Cheers,
>        Matthew
>

--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/



--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Dealing with optional attributes

Joseph Lawrence
In reply to this post by mjgraham
Hi Mathew,
    Please find as attachment a sample test case I created from my understanding. Hope the attached sample is self explanatory and serves your requirement. Try it in the xforms-sandbox.

Thanks
Joseph Lawrence
Stabilix Solutions


Ahhh...imagining that irresistible "new car" smell?
Check out new cars at Yahoo! Autos.

--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

binding-sample.xhtml (5K) Download Attachment