2150 |
mathias |
1 |
<!--
|
|
|
2 |
This file demonstrates how the dojox.wire code can be used to do declarative
|
|
|
3 |
wiring of events. Specifically, it shows how you can wire actions to set values
|
|
|
4 |
across to other widgets, but only if certain conditions are met.
|
|
|
5 |
-->
|
|
|
6 |
<html>
|
|
|
7 |
<head>
|
|
|
8 |
<title>Conditional Actions Demo</title>
|
|
|
9 |
<style type="text/css">
|
|
|
10 |
|
|
|
11 |
@import "../../../../dijit/themes/tundra/tundra.css";
|
|
|
12 |
@import "../../../../dojo/resources/dojo.css";
|
|
|
13 |
@import "../../../../dijit/tests/css/dijitTests.css";
|
|
|
14 |
@import "../TableContainer.css";
|
|
|
15 |
|
|
|
16 |
.splitView {
|
|
|
17 |
width: 90%;
|
|
|
18 |
height: 90%;
|
|
|
19 |
border: 1px solid #bfbfbf;
|
|
|
20 |
border-collapse: separate;
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
b {
|
|
|
24 |
float: left;
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
.rJustified {
|
|
|
28 |
float: right;
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
</style>
|
|
|
32 |
|
|
|
33 |
<script type="text/javascript" src="../../../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
|
|
|
34 |
<script type="text/javascript">
|
|
|
35 |
dojo.require("dojo.parser");
|
|
|
36 |
dojo.require("dojox.wire");
|
|
|
37 |
dojo.require("dojox.wire.ml.Invocation");
|
|
|
38 |
dojo.require("dojox.wire.ml.DataStore");
|
|
|
39 |
dojo.require("dojox.wire.ml.Transfer");
|
|
|
40 |
dojo.require("dojox.wire.ml.Data");
|
|
|
41 |
dojo.require("dijit.form.TextBox");
|
|
|
42 |
dojo.require("dijit.form.CheckBox");
|
|
|
43 |
dojo.require("dijit.form.ComboBox");
|
|
|
44 |
</script>
|
|
|
45 |
</head>
|
|
|
46 |
|
|
|
47 |
<body class="tundra">
|
|
|
48 |
|
|
|
49 |
<!-- Layout -->
|
|
|
50 |
<font size="3"><b>Demo of Conditional Actions:</b></font><br/><br/>
|
|
|
51 |
This demo shows how you can use actions to read and set widget values, as well as have actions only occur if
|
|
|
52 |
if certain conditions are met, such as cloning values as they are typed from the billing address over to the
|
|
|
53 |
shipping address if the 'Use Same Address' checkbox is checked true.
|
|
|
54 |
<br/>
|
|
|
55 |
<br/>
|
|
|
56 |
<div dojoType="dojo.data.ItemFileReadStore" url="states.json" jsId="statesStore"></div>
|
|
|
57 |
<table width="100%">
|
|
|
58 |
<tr>
|
|
|
59 |
<td colspan="2" align="center">
|
|
|
60 |
Use Same Address: <div dojoType="dijit.form.CheckBox" id="useSameAddress" checked="true"></div>
|
|
|
61 |
</td>
|
|
|
62 |
</tr>
|
|
|
63 |
<tr>
|
|
|
64 |
<td>
|
|
|
65 |
<b>Billing Address</b>
|
|
|
66 |
</td>
|
|
|
67 |
<td>
|
|
|
68 |
<b>Shipping Address</b>
|
|
|
69 |
</td>
|
|
|
70 |
</tr>
|
|
|
71 |
|
|
|
72 |
<tr>
|
|
|
73 |
<td>
|
|
|
74 |
<b>Name:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="BillingName" name="billingname" value="" size="50"></div>
|
|
|
75 |
</td>
|
|
|
76 |
<td>
|
|
|
77 |
<b>Name:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="ShippingName" name="shippingname" value="" disabled="true" size="50"></div>
|
|
|
78 |
</td>
|
|
|
79 |
</tr>
|
|
|
80 |
<tr>
|
|
|
81 |
<td>
|
|
|
82 |
<b>Address 1:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="BillingAddress1" name="billingaddress1" value="" size="50"></div>
|
|
|
83 |
</td>
|
|
|
84 |
<td>
|
|
|
85 |
<b>Address 1:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="ShippingAddress1" name="shippingaddress1" value="" disabled="true" size="50"></div>
|
|
|
86 |
</td>
|
|
|
87 |
</tr>
|
|
|
88 |
<tr>
|
|
|
89 |
<td>
|
|
|
90 |
<b>Address 2:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="BillingAddress2" name="billingaddress2" value="" size="50"></div>
|
|
|
91 |
</td>
|
|
|
92 |
<td>
|
|
|
93 |
<b>Address 2:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="ShippingAddress2" name="shippingaddress2" value="" disabled="true" size="50"></div>
|
|
|
94 |
</td>
|
|
|
95 |
</tr>
|
|
|
96 |
<tr>
|
|
|
97 |
<td>
|
|
|
98 |
<b>City:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="BillingCity" name="billingcity" value="" size="50"></div>
|
|
|
99 |
</td>
|
|
|
100 |
<td>
|
|
|
101 |
<b>City:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="ShippingCity" name="shippingcity" value="" disabled="true" size="50"></div>
|
|
|
102 |
</td>
|
|
|
103 |
</tr>
|
|
|
104 |
<tr>
|
|
|
105 |
<td>
|
|
|
106 |
<b>State:</b> <div class="rJustified" dojoType="dijit.form.ComboBox" searchAttr="name" id="BillingState" name="billingstate" value="" store="statesStore" size="46"></div>
|
|
|
107 |
</td>
|
|
|
108 |
<td>
|
|
|
109 |
<b>State:</b> <div class="rJustified" dojoType="dijit.form.ComboBox" searchAttr="name" id="ShippingState" name="shippingstate" value="" store="statesStore" disabled="true" size="46"></div>
|
|
|
110 |
</td>
|
|
|
111 |
</tr>
|
|
|
112 |
<tr>
|
|
|
113 |
<td>
|
|
|
114 |
<b>Zip code:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="BillingZip" name="billingzip" value="" size="50"></div>
|
|
|
115 |
</td>
|
|
|
116 |
<td>
|
|
|
117 |
<b>Zip code:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="ShippingZip" name="shippingzip" value="" disabled="true" size="50"></div>
|
|
|
118 |
</td>
|
|
|
119 |
</tr>
|
|
|
120 |
</table>
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
<!-------------------------------- Using dojox.wire, declaratively wire up the widgets. --------------------------->
|
|
|
124 |
|
|
|
125 |
<!--
|
|
|
126 |
Enable/disable the Right hand side of the shipping address view based on the checkbox events.
|
|
|
127 |
-->
|
|
|
128 |
<div dojoType="dojox.wire.ml.Action"
|
|
|
129 |
trigger="useSameAddress"
|
|
|
130 |
triggerEvent="setChecked">
|
|
|
131 |
<!--
|
|
|
132 |
Trigger a setting of the Shipping fields' input state based on the state of the checkbox.
|
|
|
133 |
-->
|
|
|
134 |
<div dojoType="dojox.wire.ml.Invocation" object="ShippingName" method="setDisabled" parameters="arguments[0]"></div>
|
|
|
135 |
<div dojoType="dojox.wire.ml.Invocation" object="ShippingAddress1" method="setDisabled" parameters="arguments[0]"></div>
|
|
|
136 |
<div dojoType="dojox.wire.ml.Invocation" object="ShippingAddress2" method="setDisabled" parameters="arguments[0]"></div>
|
|
|
137 |
<div dojoType="dojox.wire.ml.Invocation" object="ShippingCity" method="setDisabled" parameters="arguments[0]"></div>
|
|
|
138 |
<div dojoType="dojox.wire.ml.Invocation" object="ShippingState" method="setDisabled" parameters="arguments[0]"></div>
|
|
|
139 |
<div dojoType="dojox.wire.ml.Invocation" object="ShippingZip" method="setDisabled" parameters="arguments[0]"></div>
|
|
|
140 |
</div>
|
|
|
141 |
|
|
|
142 |
<!--
|
|
|
143 |
Clone the values of form fields while typing based on the setting of the checkbox.
|
|
|
144 |
-->
|
|
|
145 |
<div dojoType="dojox.wire.ml.Action"
|
|
|
146 |
trigger="BillingName"
|
|
|
147 |
triggerEvent="onkeyup">
|
|
|
148 |
<div dojoType="dojox.wire.ml.ActionFilter" required="useSameAddress.checked" requiredValue="true" type="boolean"></div>
|
|
|
149 |
<div dojoType="dojox.wire.ml.Transfer" source="BillingName.value" target="ShippingName.value"></div>
|
|
|
150 |
</div>
|
|
|
151 |
<div dojoType="dojox.wire.ml.Action"
|
|
|
152 |
trigger="BillingAddress1"
|
|
|
153 |
triggerEvent="onkeyup">
|
|
|
154 |
<div dojoType="dojox.wire.ml.ActionFilter" required="useSameAddress.checked" requiredValue="true" type="boolean"></div>
|
|
|
155 |
<div dojoType="dojox.wire.ml.Transfer" source="BillingAddress1.value" target="ShippingAddress1.value"></div>
|
|
|
156 |
</div>
|
|
|
157 |
<div dojoType="dojox.wire.ml.Action"
|
|
|
158 |
trigger="BillingAddress2"
|
|
|
159 |
triggerEvent="onkeyup">
|
|
|
160 |
<div dojoType="dojox.wire.ml.ActionFilter" required="useSameAddress.checked" requiredValue="true" type="boolean"></div>
|
|
|
161 |
<div dojoType="dojox.wire.ml.Transfer" source="BillingAddress2.value" target="ShippingAddress2.value"></div>
|
|
|
162 |
</div>
|
|
|
163 |
<div dojoType="dojox.wire.ml.Action"
|
|
|
164 |
trigger="BillingCity"
|
|
|
165 |
triggerEvent="onkeyup">
|
|
|
166 |
<div dojoType="dojox.wire.ml.ActionFilter" required="useSameAddress.checked" requiredValue="true" type="boolean"></div>
|
|
|
167 |
<div dojoType="dojox.wire.ml.Transfer" source="BillingCity.value" target="ShippingCity.value"></div>
|
|
|
168 |
</div>
|
|
|
169 |
<div dojoType="dojox.wire.ml.Action"
|
|
|
170 |
trigger="BillingState"
|
|
|
171 |
triggerEvent="onChange">
|
|
|
172 |
<div dojoType="dojox.wire.ml.ActionFilter" required="useSameAddress.checked" requiredValue="true" type="boolean"></div>
|
|
|
173 |
<div dojoType="dojox.wire.ml.Transfer" source="BillingState.value" target="ShippingState.value"></div>
|
|
|
174 |
</div>
|
|
|
175 |
|
|
|
176 |
<div dojoType="dojox.wire.ml.Action"
|
|
|
177 |
trigger="BillingZip"
|
|
|
178 |
triggerEvent="onkeyup">
|
|
|
179 |
<div dojoType="dojox.wire.ml.ActionFilter" required="useSameAddress.checked" requiredValue="true" type="boolean"></div>
|
|
|
180 |
<div dojoType="dojox.wire.ml.Transfer" source="BillingZip.value" target="ShippingZip.value"></div>
|
|
|
181 |
</div>
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
<!--
|
|
|
185 |
Clone the values of form fields from billing over to shipping over if the
|
|
|
186 |
useSameAddress checkbox is set back to true.
|
|
|
187 |
-->
|
|
|
188 |
<div dojoType="dojox.wire.ml.Action"
|
|
|
189 |
trigger="useSameAddress"
|
|
|
190 |
triggerEvent="setChecked">
|
|
|
191 |
<div dojoType="dojox.wire.ml.ActionFilter" required="arguments[0]" requiredValue="true" type="boolean"></div>
|
|
|
192 |
|
|
|
193 |
<!--
|
|
|
194 |
Note that this uses the basic 'property' form of copying the property over and setting it. The Wire
|
|
|
195 |
code supports both getX and setX functions of setting a property as well as direct access. It first looks
|
|
|
196 |
for the getX/setX functions and if present, uses them. If missing, it will just do direct access. Because
|
|
|
197 |
of the standard getValue/setValue API of dijit form widgets, transfers work well and are compact.
|
|
|
198 |
-->
|
|
|
199 |
<div dojoType="dojox.wire.ml.Transfer" source="BillingName.value" target="ShippingName.value"></div>
|
|
|
200 |
<div dojoType="dojox.wire.ml.Transfer" source="BillingAddress1.value" target="ShippingAddress1.value"></div>
|
|
|
201 |
<div dojoType="dojox.wire.ml.Transfer" source="BillingAddress2.value" target="ShippingAddress2.value"></div>
|
|
|
202 |
<div dojoType="dojox.wire.ml.Transfer" source="BillingCity.value" target="ShippingCity.value"></div>
|
|
|
203 |
<div dojoType="dojox.wire.ml.Transfer" source="BillingState.value" target="ShippingState.value"></div>
|
|
|
204 |
<div dojoType="dojox.wire.ml.Transfer" source="BillingZip.value" target="ShippingZip.value"></div>
|
|
|
205 |
</div>
|
|
|
206 |
|
|
|
207 |
</body>
|
|
|
208 |
</html>
|