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.
188 lines (177 loc) • 7.06 kB
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" data-dojo-config="parseOnLoad:1,isDebug:1,async:1,mvc:{debugBindings:1}" src="../../../dojo/dojo.js"></script>
<script type="text/javascript">
var model;
require([
'dojo/_base/kernel',
'dojo/parser',
'dojo/ready',
"dojox/mvc/getStateful",
"dojox/mvc/EditModelRefController",
'dijit/form/TextBox',
'dijit/form/Button',
'dijit/form/ValidationTextBox',
'dijit/form/NumberTextBox',
'dojox/mvc/Group',
'dojox/mvc/Output'
], function(dojo, parser, ready, getStateful, EditModelRefController){
model = new EditModelRefController({sourceModel: getStateful({ "First" : "John",
"Last" : "Doe",
"Email" : "jdoe@example.com",
"Num" : 3
})});
console.log("model is ");
console.log(model);
function noParse(){
throw new Error();
}
nameReadOnlyConverter = {
format: function(value){
return value === "2" || value === "3";
},
parse: noParse
};
nameRelevanceConverter = {
format: function(value){
return value == "0";
},
parse: noParse
};
nameRequiredConverter = {
format: function(value){
return value === "4";
},
parse: noParse
};
numValidConverter = {
format: function(value){
return value - 0 !== 1 && value !== "3";
},
parse: noParse
};
disabledDisplayConverter = {
format: function(value){
// if(value){
return "disabled is "+value;
// }
// return value - 0 !== 1 && value !== "3";
},
parse: function(value){
// if(value){
return "disabled is "+value;
// }
// return value - 0 !== 1 && value !== "3";
}
};
});
</script>
</head>
<body class="claro">
<script type="dojo/require">at: "dojox/mvc/at"</script>
<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 disable 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="value: at(model, 'First'),
readOnly: at(model, 'First').transform(nameReadOnlyConverter),
disabled: at(model, 'First').transform(nameRelevanceConverter),
valid: at(model, 'First').transform(numValidConverter)"></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="value: at(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="value: at(model, 'First')">
disable is: ${this.ref.disable}, 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="value: at(model, 'Num'),
valid: at(model, 'Num').transform(numValidConverter)"></input>
<span data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at(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 disable 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="value: at(model, 'Last')"></input>
<span data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at(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="value: at(model, 'Email'),
readOnly: at(model, 'Last').transform(nameReadOnlyConverter),
disabled: at(model, 'Last').transform(nameRelevanceConverter),
valid: at(model, 'Last').transform(numValidConverter),
required: at(model, 'Last').transform(nameRequiredConverter)"></input>
<span data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at(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="value: at(model, 'Email'),
readOnly: at(model, 'Email'),
disabled: at(model, 'Email').transform(disabledDisplayConverter),
required: at(model, 'Email')">
disabled is: ${this.disabled}, Valid is: ${this.valid}, Read-only is: ${this.readOnly}, Required is: ${this.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>