Hub Nexus
Atualizada

AutorAinda sem autorAssumir

Viu algo para melhorar? Proponha uma alteração.

Apoio

Em XForms · página 53 de 137

Motivation

You have a list of items and you want a simple way of conditionally displaying fields within a repeated group.

Method

We will do this is two ways. First we will use a bind expression in the model. The second method of doing this will be to use a group element with a ref attribute.

Sample Data

xmlns="">

yes
display 1

no
display 2

yes
display 3

Sample Repeat

nodeset="instance('my-data')/group" id="my-repeat">

Group # value="count(preceding-sibling::*) +1">

ref="code">
Display Input Field:

Yes
yes

No
no

ref="field" >
Conditional Display:

Solution Using Relative Binds

In this example we use a relative statement to indicate that the field should only be displayed if the code value is "yes". Note that the context of the relevant expression is the result of each nodeset item.

id="field"
nodeset="instance('my-data')/group/field"
relevant="../code = 'yes'"/>

Solution Using Group Element

We can use the ref attribute to conditionally display any field within a repeat. We do this by starting the group ref attribute with "." to give it the current context. Then we add a predicate to turn on or off that entire group. In this case if the code is "yes" the input field will be displayed. If it is not the field will be hidden.

ref=".[code='yes']">
ref="field">
Conditional Display:

Complete Example

xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms">;

Binds in Repeats
type="text/css">
@namespace xf url("http://www.w3.org/2002/xforms");
body {{
font-family:Helvetica, sans-serif;
}}

id="my-data">
xmlns="">

yes
display 1

no
display 2

yes
display 3

no
display 4

id="field"
nodeset="instance('my-data')/group/field"
relevant="../code = 'yes'"/>

Test of binding rules within a repeat
nodeset="instance('my-data')/group" id="my-repeat">

Group # value="count(preceding-sibling::*) +1">

ref="code">
Display Input Field:

Yes
yes

No
no

ref="field" >
Conditional Display:

value="index('my-repeat')">
Current Selected Group:

Where this page came from

This page was imported from Wikibooks. From “XForms” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

Nestas publicaçõesXForms

IdiomasEnglish

Licença: CC BY-SA 4.0 · Adaptado de en.wikibooks.org

1

0

0

0

Spinner Logo

Comentários

Spinner Logo
Versão: 2CC0 1.0 — public domain
The runaway star that left the Tarantula Nebula
Versão: 2CC0 1.0 — public domain
The Blackwell School, where segregation had no law behind it
Versão: 2CC0 1.0 — public domain
The Eagle Nebula, seen in the infrared
Versão: 2CC0 1.0 — public domain
The house where the Equal Rights Amendment was written
Versão: 2CC0 1.0 — public domain
The Aleutians, the forgotten front of the Second World War
Versão: 2CC0 1.0 — public domain
The Cosmic Cliffs are not cliffs