checkboxes - at least one required

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

checkboxes - at least one required

rakkie
Hi,

I have these three elements which I want to be gerenerated as checkboxes
<alcoholic_beverage_items>
   <alcoholic_beverage>
        <type>beer</type>
        <value>false</value>
   </alcoholic_beverage>
   <alcoholic_beverage>
        <type>wine</type>
        <value>false</value>
   </alcoholic_beverage>
    <alcoholic_beverage>
         <type>liquor</type>
         <value>false</value>
    </alcoholic_beverage>
</alcoholic_beverage_items>

To make them checkboxes I bound them to xs:boolean:
<xforms:bind nodeset="alcoholic_beverage_items">
    <xforms:bind nodeset="alcoholic_beverage[type='beer']/value" type="xs:boolean"/>
    <xforms:bind nodeset="alcoholic_beverage[type='wine']/value" type="xs:boolean"/>
   <xforms:bind nodeset="alcoholic_beverage[type='liquor']/value" type="xs:boolean"/>
 </xforms:bind>

However when it comes to constraints I don't really know what to do. I need a check that at least one of them are selected. Otherwise an alert should show. Anyone with any ideas? (The element structure could be changed if that would help...)


//Robert



--
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: checkboxes - at least one required

fl.schmitt(ops-users)
Robert,

> To make them checkboxes I bound them to xs:boolean:
> <xforms:bind nodeset="alcoholic_beverage_items">
>     <xforms:bind nodeset="alcoholic_beverage[type='beer']/value"
> type="xs:boolean"/>
>     <xforms:bind nodeset="alcoholic_beverage[type='wine']/value"
> type="xs:boolean"/>
>    <xforms:bind nodeset="alcoholic_beverage[type='liquor']/value"
> type="xs:boolean"/>
>  </xforms:bind>

> However when it comes to constraints I don't really know what to do. I
> need a check that at least one of them are selected. Otherwise an alert
> should show. Anyone with any ideas? (The element structure could be
> changed if that would help...)

I assume you've defined separate xforms controls for each of the
<alcoholic_beverage_items> items. This isn't mandatory. You could
alternatively just define one instance node that holds the selected
values. For example: <beverages>beer liquor</beverages>. In your XForms
code, you could use <xforms:select ref=".../beverages"
appearance="full">. This creates checkboxes for each of the selectable
items [1].

To define the selectable items, you could either define them inside
<xforms:select>...</xforms:select> as shown in the docs [1], or put them
into a separate instance and let the xforms engine pull them out using
itemset (there's an example how to do this at the bottom of the XForms
controls table at [1]).

To make at least one selection mandatory, just check if the instance
element receiving the selection is empty or not - in my example, just
check the <beverages> element for content (e.g. using a bind
nodeset="../beverages" constraint="string-length(.) gt 1"). If at least
one item is selected, its value is put into that element; multiple items
are put together in that element divided by a ' '.

hth
florian

[1]
http://www.orbeon.com/orbeon/doc/reference-xforms-guide#xforms-controls-list




--
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
|

[SOLVED] SV: Re: checkboxes - at least one required

rakkie
Hi Florian,

Thanks alot! That worked perfectly!

/Robert


--- Den mån 2010-04-26 skrev Florian Schmitt <[hidden email]>:

Från: Florian Schmitt <[hidden email]>
Ämne: [ops-users] Re: checkboxes - at least one required
Till: [hidden email]
Datum: måndag 26 april 2010 12:28

Robert,

> To make them checkboxes I bound them to xs:boolean:
> <xforms:bind nodeset="alcoholic_beverage_items">
>     <xforms:bind nodeset="alcoholic_beverage[type='beer']/value"
> type="xs:boolean"/>
>     <xforms:bind nodeset="alcoholic_beverage[type='wine']/value"
> type="xs:boolean"/>
>    <xforms:bind nodeset="alcoholic_beverage[type='liquor']/value"
> type="xs:boolean"/>
>  </xforms:bind>

> However when it comes to constraints I don't really know what to do. I
> need a check that at least one of them are selected. Otherwise an alert
> should show. Anyone with any ideas? (The element structure could be
> changed if that would help...)

I assume you've defined separate xforms controls for each of the
<alcoholic_beverage_items> items. This isn't mandatory. You could
alternatively just define one instance node that holds the selected
values. For example: <beverages>beer liquor</beverages>. In your XForms
code, you could use <xforms:select ref=".../beverages"
appearance="full">. This creates checkboxes for each of the selectable
items [1].

To define the selectable items, you could either define them inside
<xforms:select>...</xforms:select> as shown in the docs [1], or put them
into a separate instance and let the xforms engine pull them out using
itemset (there's an example how to do this at the bottom of the XForms
controls table at [1]).

To make at least one selection mandatory, just check if the instance
element receiving the selection is empty or not - in my example, just
check the <beverages> element for content (e.g. using a bind
nodeset="../beverages" constraint="string-length(.) gt 1"). If at least
one item is selected, its value is put into that element; multiple items
are put together in that element divided by a ' '.

hth
florian

[1]
http://www.orbeon.com/orbeon/doc/reference-xforms-guide#xforms-controls-list



-----Infogad bilaga följer-----


--
You receive this message as a subscriber of the ops-users@... mailing list.
To unsubscribe: mailto:ops-users-unsubscribe@...
For general help: mailto:sympa@...?subject=help
OW2 mailing lists service home page: http://www.ow2.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
OW2 mailing lists service home page: http://www.ow2.org/wws