-
Notifications
You must be signed in to change notification settings - Fork 2
/
sample.html
66 lines (60 loc) · 3.18 KB
/
sample.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/resources/dojo.css">
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/tundra/tundra.css">
<script src="http://github.com/downloads/SteveSanderson/knockout/knockout-1.2.1.js"></script>
<script>djConfig = {parseOnLoad: true};</script>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/dojo.xd.js"></script>
<script src="ko_dojo.js"></script>
<script>
dojo.require("dijit.form.Button");
dojo.require("dijit.form.TextBox");
dojo.require("dijit.form.CurrencyTextBox");
dojo.require("dijit.form.CheckBox");
dojo.require("dijit.form.RadioButton");
dojo.require("dijit.form.Form");
dojo.require("dojo.parser");
var viewModel = {
firstName: ko.observable(),
amount: ko.observable(),
textAmount: ko.observable(),
agree: ko.observable(),
drink: ko.observable()
};
viewModel.message = ko.dependentObservable(function(){
if (this.firstName() && this.textAmount())
return "Hello, " + this.firstName() + ", you owe me " + this.textAmount();
}, viewModel);
dojo.ready(function(){
ko.applyBindings(viewModel);
bindDojoAndKnockout({elementId: 'firstName', observable: viewModel.firstName});
bindDojoAndKnockout({elementId: 'amount', observable: viewModel.amount});
bindDojoAndKnockout({
elementId: 'amount',
observable: viewModel.textAmount,
elementAttribute: 'displayedValue',
knockoutObservableHandler: null // we don't have to react on changing viewModel.textAmount
});
bindDojoAndKnockout({elementId: 'agree', elementAttribute: 'checked', observable: viewModel.agree});
bindDojoAndKnockout({elements: 'input[type=radio]', observable: viewModel.drink})
});
</script>
</head>
<body class="tundra">
<input type="text" name="firstName" data-dojo-type="dijit.form.TextBox" id="firstName">
<input type="text" name="amount" data-dojo-type="dijit.form.CurrencyTextBox" id="amount">
<input type="checkbox" name="agree" data-dojo-type="dijit.form.CheckBox" id="agree"> <span data-bind="visible: agree">agree!</span> <br />
<p data-bind="text: message"></p>
<form id="radioForm" data-dojo-type="dijit.form.Form">
<label>
<input type="radio" name="drink" dojoType="dijit.form.RadioButton" value="coffee" id="coffeeButton"> Coffee
</label>
<label>
<input type="radio" name="drink" dojoType="dijit.form.RadioButton" value="tea" id="teaButton"> Tea
</label>
</form>
<p data-bind="visible: drink">You have chosen <span data-bind="text: drink"></span></p>
</body>
</html>