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

Re: absent vs empty attributes

From: Florian Lacoste <florian.lacoste@evidian.com>
Date: Thu, 02 Feb 2006 11:24:09 +0100
Message-ID: <43E1DDC9.2090708@evidian.com>
To: www-forms@w3.org

- wrote:
> I have a question about attributes which have required values, but  the 
> attribute itself is optional.  I'm attempting to bind an XForm  checkbox 
> to an attribute, called keyDate, which is defined in the  following Schema:
> <xsd:attribute name="keyDate" use="optional">
>   <xsd:simpleType>
>     <xsd:restriction base="xsd:string">
>       <xsd:enumeration value="yes"/>
>     </xsd:restriction>
>   </xsd:simpleType>
> </xsd:attribute>
> So the only valid instance document would be one where the keyDate  
> attribute is absent, or one where it is present and contains "yes" as  
> the value.  My preferred behavior for this would be the production of  
> an instance document without the attribute when the box is unchecked,  
> but if checked the attribute's value would be set.  Is this  possible?  
> Have others come up with solutions for this scenario?
> If it helps, below is my XForms control, as it is used in OPS:
>                   <xforms:select ref="@keyDate" appearance="full">
>                     <xforms:label class="fixed-width  
> attribute">keyDate: </xforms:label>
>                     <xforms:item>
>                       <xforms:label>yes</xforms:label>
>                       <xforms:value>yes</xforms:value>
>                     </xforms:item>
>                   </xforms:select>


I tried to do something like that once. The solution I found was a 
little complicated for what it did but anyway:

Define a "flag" attribute in another instance or in a non submitted part 
of your instance. Its value is true(). Then define the relevant 
attribute for keyDate: relevant=". = 'yes' or /path_to_flag"

Then add an event switching the flag value to false() on submit and 
another switching its value to true() on submit-error.

The flag being always true when you display the form, your keyDate will 
show and as it switches to false on submitting the data, it will be 
submitted only if its value is "yes". In case of a submit error, it goes 
back to true, thus keyDate is still displayed.

I did that when I was just a beginner in XForms, it worked. There is 
surely a better way but I never thought about it since.

Hope that helps. Regards,

Received on Thursday, 2 February 2006 10:33:11 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:36:16 UTC