| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 | <title>Simple programmatic data binding - Toggle example</title> |
| 6 | |
| 7 | <script src="../../../../dojo/dojo.js" |
| 8 | type="text/javascript" |
| 9 | djConfig="parseOnLoad: true, isDebug: true"> |
| 10 | </script> |
| 11 | <style type="text/css"> |
| 12 | @import "css/app-format.css"; |
| 13 | @import "../../../../dijit/themes/claro/claro.css"; |
| 14 | </style> |
| 15 | <script type="text/javascript" > |
| 16 | dojo.require("dojox.mvc"); |
| 17 | dojo.require("dijit.form.TextBox"); |
| 18 | dojo.require("dijit.form.Button"); |
| 19 | dojo.require("dojo.parser"); |
| 20 | |
| 21 | // Function below shows programmatic creation of data-bound dijits |
| 22 | function addBoundDijits(){ |
| 23 | var model = dojox.mvc.newStatefulModel({ data: { first: "John", last: "Doe" }}); |
| 24 | |
| 25 | var fn = new dijit.form.TextBox({id: "fn", ref: model.first}); |
| 26 | fn.placeAt(dojo.byId("mainContent")); |
| 27 | fn.startup(); |
| 28 | |
| 29 | var ln = new dijit.form.TextBox({id: "ln", ref: model.last}); |
| 30 | ln.placeAt(dojo.byId("mainContent")); |
| 31 | ln.startup(); |
| 32 | } |
| 33 | |
| 34 | // Function below shows programmatic update of data-bound dijit refs |
| 35 | function toggleRefs(){ |
| 36 | var fn = dijit.byId("fn"), ln = dijit.byId("ln"); |
| 37 | var ref = fn.get("ref"); |
| 38 | fn.set("ref", ln.get("ref")); |
| 39 | ln.set("ref", ref); |
| 40 | } |
| 41 | |
| 42 | dojo.addOnLoad(addBoundDijits); |
| 43 | </script> |
| 44 | </head> |
| 45 | <body class="claro"> |
| 46 | <div id="wrapper"> |
| 47 | <div id="header"> |
| 48 | <div id="navigation"> |
| 49 | </div> |
| 50 | <div id="headerInsert"> |
| 51 | <h1>Toggle</h1> |
| 52 | <h2>Simple Example - Programmatic data binding.</h2> |
| 53 | </div> |
| 54 | </div> |
| 55 | <div id="main"> |
| 56 | <div id="leftNav"> |
| 57 | </div> |
| 58 | <div id="mainContent"> |
| 59 | <button id="toggle" type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: toggleRefs">Toggle Refs</button> |
| 60 | </div> |
| 61 | </div> |
| 62 | </div> |
| 63 | </body> |
| 64 | </html> |