Re: How to ensure that at least one of 2 attributes is set to true

Hi Manfred,

Yes, you can do this too. 

You have the freedom to attach the constraint to any data node you like, 
and a form control does not have to be bound to that data node.

The failure of a constraint will still produce an xforms-submit-error with 
error-type validation-error even if no form controls are bound to the 
node.  It only needs to be part of the data being submitted.

In your case, this means you can create a handler for the 
xforms-submit-error that informs the user there is an error without having 
to immediately report a problem on the form controls bound to the two 
attributes.  The constraint could be attached to the element containing 
the two attributes, rather than to one or both of the attributes. 
Something like this:

<xf:bind nodeset="im:objektkategorie/im:vermarktungsart"
         constraint="boolean-from-string(@MIETE_PACHT) or 
boolean-from-string(@KAUF)" />

Finally, if you have yet another form control bound to the element node, 
say it has the attributes but also simple content to be input by the user, 
then you can attach the constraint to any ancestor element, all the way up 
to the root of whatever instance data being submitted.

Cheers,
John M. Boyer, Ph.D.
STSM, Interactive Documents and Web 2.0 Applications
Chair, W3C Forms Working Group
Workplace, Portal and Collaboration Software
IBM Victoria Software Lab
E-Mail: boyerj@ca.ibm.com 

Blog: http://www.ibm.com/developerworks/blogs/page/JohnBoyer
Blog RSS feed: 
http://www.ibm.com/developerworks/blogs/rss/JohnBoyer?flavor=rssdw





From:
Manfred Staudinger <manfred.staudinger@gmail.com>
To:
Nick Van den Bleeken <Nick_Van_den_Bleeken@inventivegroup.com>
Cc:
"www-forms@w3.org" <www-forms@w3.org>
Date:
06/22/2009 04:07 AM
Subject:
Re: How to ensure that at least one of 2 attributes is set to true



Hi Nick Van den Bleeken,

Thanks for showing me the use of the constraint attribute! Works fine
and I'll use it in many other cases too.

One minor problem remains: would it be possible to delay the error msg
/ display until later (maybe submit)? Currently I simply have:
                                                 /* Display a red 
background on all invalid form controls */
                                                 *:invalid 
{background-color:red;}

Regards,

Manfred Staudinger




On 22/06/2009, Nick Van den Bleeken
<Nick_Van_den_Bleeken@inventivegroup.com> wrote:
> Hi Manfred Staudinger;
>
> You can add additional constraints to your instance data by using the
> constraint[1] attribute on a bind (an invalid instance can't be 
submitted,
> so this also solves your store problem).
>
> In your example:
> <xf:bind nodeset="im:objektkategorie/im:vermarktungsart/@MIETE_PACHT"
> type="xs:boolean" constraint="boolean-from-string(.) or
> boolean-from-string(../@KAUF)" />
>
> Makes the miete_pacht attribute valid if either miete_pacht or kauf is 
true.
> To show a warning you can use the alert element on the input that binds 
to
> miete_pacht attribute.
>
> In your example:
>
> <xf:input ref="im:objektkategorie/im:vermarktungsart/@KAUF">
>   <xf:label>Verkauf: &nbsp;</xf:label>
>   <xf:alert>Either verkauf or Vermietung should be checked</xf:alert>
> </xf:input>
>
>
> Regards,
>
> Nick Van den Bleeken
> R&D Manager
>
> Phone: +32 3 821 01 70
> Office Fax: +32 3 821 01 71
> Nick_Van_den_Bleeken@inventivegroup.com
> http://www.inventivegroup.com
>
> 1:
> 
http://www.w3.org/MarkUp/Forms/specs/XForms1.1/index-diff.html#model-prop-constraint

>
>
>> -----Original Message-----
>> From: www-forms-request@w3.org [mailto:www-forms-request@w3.org] On
>> Behalf Of Manfred Staudinger
>> Sent: zondag 21 juni 2009 22:10
>> To: www-forms@w3.org
>> Subject: How to ensure that at least one of 2 attributes is set to true
>>
>> Hi List,
>>
>> I'm new to XForms, read a lot but still missing something: I did not
>> find a solution (other than post-processing with xslt). I want to make
>> sure that at least one of the 2 attributes
>> (MIETE_PACHT, KAUF) is set to true (1). If this is not the case, I
>> would like to get a message or even prevent the document from being
>> stored.
>> Here is my instance and the bind:
>> <xf:model>
>>    <xf:instance xmlns="http://www.example.com">
>>    <immobilie>
>>       <objektkategorie>
>>          <vermarktungsart MIETE_PACHT="0" KAUF="0" />
>>       </objektkategorie>
>>    </immobilie>
>>    </xf:instance>
>>
>>    <xf:bind
>> nodeset="im:objektkategorie/im:vermarktungsart/@MIETE_PACHT"
>> type="xs:boolean"  />
>>    <xf:bind nodeset="im:objektkategorie/im:vermarktungsart/@KAUF"
>> type="xs:boolean"  />
>>    <xf:submission id="saveDoc" method="put">
>>       <xf:resource value="concat('test/fertigobjekt',
>> im:verwaltung_techn/ic:objektnr, '.xml')"/>
>>    </xf:submission>
>> </xf:model>
>>
>> Input fields are:
>> <xf:group>
>>    <xf:input ref="im:objektkategorie/im:vermarktungsart/@KAUF">
>>       <xf:label>Verkauf: &nbsp;</xf:label>
>>    </xf:input>
>>    <xf:input ref="im:objektkategorie/im:vermarktungsart/@MIETE_PACHT">
>>       <xf:label>Vermietung (Miete, Pacht): &nbsp;</xf:label>
>>    </xf:input>
>> </xf:group>
>>
>> Remarks about the example above and pointers to sources are also
>> appreciated. Thanks!
>>
>> Manfred Staudinger
>>
>>
>>
>> --
>> This message has been scanned for viruses and
>> dangerous content by MailScanner, and is
>> believed to be clean.
>> --
>>
>
>
> Inventive Designers' Email Disclaimer:
> http://www.inventivedesigners.com/email-disclaimer
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
> --
>
>
>

Received on Monday, 22 June 2009 16:44:55 UTC