dojo - Cannot get a reference to a dijit form when the form has a DateTextBox -
i having trouble getting reference dijit form widget when form contains datetextbox. code snippet below demonstrates problem. when executed, alert box says "undefined". however, if rid of <input ... id="datetextbox"... />
, able reference form widget.
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title></title> <link rel="stylesheet" type="text/css" href="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dijit/themes/claro/claro.css" media="screen"> <!-- load dojo , provide config via data attribute --> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.js" data-dojo-config="async: true, parseonload: true"> </script> <script type="text/javascript"> require(["dijit/form/textbox", "dijit/form/datetextbox"]); </script> <script type="text/javascript"> require(["dojo/parser", "dijit/registry", "dijit/form/form", "dojo/domready!"], function(parser, registry) { parser.parse(); alert(registry.byid("frm_test")); }); </script> </head> <body class="claro"> <div data-dojo-type="dijit/form/form" id="frm_test" enctype="multipart/form-data" action="" method=""> <input type="text" id="textbox" name="textbox" data-dojo-type="dijit/form/textbox" /> <input type="text" id="datetextbox" name="datetextbox" data-dojo-type="dijit/form/datetextbox" /> </div> </body> </html>
i'd recommend wrapping registry.byid
ready
call.
keep parse onload: true
, remove
require(["dijit/form/textbox", "dijit/form/datetextbox"]);
as parser auto require (when dojo>= 1.8) , use following:
<script type="text/javascript"> require(["dojo/ready", "dijit/registry", "dojo/domready!"], function(ready, registry) { // default prioirty of ready call after // ready call used parse when parseonload true ready(function() { alert(registry.byid("frm_test")); }); }); </script>
note waiting dojo/domready! fire not sufficient when working widgets. many widgets shouldn’t initialized or accessed until following modules load , execute:
- dojo/uacss
- dijit/hccss
- dojo/parser
thus when working widgets should put code inside of dojo/ready() callback
http://dojotoolkit.org/reference-guide/1.9/dojo/domready.html
http://dojotoolkit.org/reference-guide/1.9/dojo/ready.html#dojo-ready
Comments
Post a Comment