UNPKG

dojox

Version:

Dojo eXtensions, a rollup of many useful sub-projects and varying states of maturity – from very stable and robust, to alpha and experimental. See individual projects contain README files for details.

183 lines (166 loc) 7.04 kB
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <title>Static Master/Detail Pattern -- Binding Test</title> <style type="text/css"> @import "css/app-format.css"; @import "../../../../dijit/themes/claro/claro.css"; </style> <script type="text/javascript" djConfig="parseOnLoad:1,isDebug:1,async:1" src="../../../../dojo/dojo.js"></script> <script type="text/javascript"> var model; require([ 'dojo/_base/kernel', 'dojo/parser', 'dojo/ready', 'dojox/mvc', 'dijit/form/TextBox', 'dijit/form/Button', 'dijit/form/ValidationTextBox', 'dijit/form/NumberTextBox', 'dojox/mvc/Group', 'dojox/mvc/Output' ], function(dojo, parser, ready, mvc){ // The dojox.mvc.StatefulModel class creates a data model instance // where each leaf within the data model is decorated with dojo.Stateful // properties that widgets can bind to and watch for their changes. model = mvc.newStatefulModel({ data : { "First" : "John", "Last" : "Doe", "Email" : "jdoe@example.com", "Num" : 3 } }); console.log("model is "); console.log(model); function testFirstRelevance(newValue) { //newValue = model.First.value; if ( newValue !== "0" ) return true; else return false; } function testFirstReadOnly(newValue) { if ( newValue !== "2" && newValue !== "3" ) return false; else return true; } function testNumValid(newValue) { if ( newValue !== 1 && newValue !== "1" && newValue !== "3") return true; else return false; } function testRequired(newValue) { if ( newValue !== 4 && newValue !== "4") return false; else return true; } function testLastRelevance(newValue) { //newValue = model.First.value; if ( newValue !== "0" ) return true; else return false; } function testLastValid(newValue) { if ( newValue !== "1" ) return true; else return false; } function init(){ // bind tests, "read-only" etc. mvc.bind(model.First, "value", model.First, "readOnly", testFirstReadOnly, true); mvc.bind(model.First, "value", model.First, "relevant", testFirstRelevance, true); mvc.bind(model.First, "value", model.First, "valid", testNumValid, true); mvc.bind(model.Num, "value", model.Num, "valid", testNumValid, true); // bind tests bind Last value to Email relevant and valid mvc.bind(model.Last, "value", model.Email, "relevant", testFirstRelevance, true); mvc.bind(model.Last, "value", model.Email, "valid", testNumValid, true); mvc.bind(model.Last, "value", model.Email, "readOnly", testFirstReadOnly, true); mvc.bind(model.Last, "value", model.Email, "required", testRequired, true); mvc.bind(model.Last, "value", model.Email, "value"); } ready(init); }); </script> </head> <body class="claro"> <div id="wrapper"> <div id="header"> <div id="navigation"> </div> <div id="headerInsert"> <h1>Binding Tests</h1> </div> </div> <div id="main"> <div id="leftNav"> </div> <div id="mainContent"> <h2>Bind Self Tests</h2> <div class="row"> <label style="display:inline-block; width:100%; text-align:left;">First: Enter 0 to test for Relevant false (disabled) (use Reset to re-enable)</label> <label style="display:inline-block; width:100%; text-align:left;">First: Enter 1 to test for Valid false.</label> <label style="display:inline-block; width:100%; text-align:left;">First: Enter 2 to test for Read-only false (use Reset to re-enable)</label> <label style="display:inline-block; width:100%; text-align:left;">First: Enter 3 to test for Read-only false and Valid false (use Reset to re-enable)</label> </div> <div class="row"> <label class="cell" for="firstnameInput">First:</label> <input class="cell" id="firstnameInput" data-dojo-type="dijit.form.ValidationTextBox" data-dojo-props="ref: model.First"></input> <!-- Content in output below will always be in sync with value of textbox above --> <span id="tout" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.First"> (first name is: ${this.value}) </span> </div> <div class="row"> <label class="cell" for="firstnameInput"></label> <span data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.First"> Relevant is: ${this.ref.relevant}, Valid is: ${this.ref.valid}, Read-only is: ${this.ref.readOnly}) </span> </div> <div class="row"> <label style="display:inline-block; width:100%; text-align:left;">Num: Enter 1 for Valid false</label> </div> <div class="row"> <label class="cell" for="numInput">Num:</label> <input class="cell" id="numInput" data-dojo-type="dijit.form.NumberTextBox" data-dojo-props="ref: model.Num"></input> <span data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.Num"> (num is: ${this.value}) </span> </div> <h2>Bind Tests</h2> <div class="row"> <label style="display:inline-block; width:100%; text-align:left;">Last: Enter 0 to test for Relevant false (disabled) for Email.</label> <label style="display:inline-block; width:100%; text-align:left;">Last: Enter 1 to test for Valid false for Email.</label> <label style="display:inline-block; width:100%; text-align:left;">Last: Enter 2 to test for Read-only true for Email.</label> <label style="display:inline-block; width:100%; text-align:left;">Last: Enter 3 to test for Read-only true and Valid false for Email.</label> <label style="display:inline-block; width:100%; text-align:left;">Last: Enter 4 to test for Required true for Email.</label> </div> <div class="row"> <label class="cell" for="lastnameInput">Last:</label> <input class="cell" id="lastnameInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: model.Last"></input> <span data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.Last"> (last name is: ${this.value}) </span> </div> <div class="row"> <label class="cell" for="emailInput">Email:</label> <input class="cell" id="emailInput" data-dojo-type="dijit.form.ValidationTextBox" data-dojo-props="ref: model.Email"></input> <span data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.Email"> (email is: ${this.value}) </span> </div> <div class="row"> <label class="cell" for="emailInput"></label> <span id="emailOut" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.Email"> Relevant is: ${this.ref.relevant}, Valid is: ${this.ref.valid}, Read-only is: ${this.ref.readOnly}, Required is: ${this.ref.required}) </span> </div> <br/>Model: <button id="reset" type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){doReset()}">Reset</button> </div> </div></div> <script type="text/javascript"> function doReset() { model.reset(); } </script> </body> </html>