Есть что улучшить? Предложите правку.
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.
В изданияхXForms
Лицензия: CC BY-SA 4.0 · По материалам en.wikibooks.org
1
0
0
0

Комментарии






