dojo-data-type is not working

1.5k Views Asked by At

Guys am unable to use the dijit widgets in HTML5 code. Its working completely fine with the legacy code dojoType. What is wrong with the HTML5 code ?

<!DOCTYPE >
<html>
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="js/dijit/themes/tundra/tundra.css">
  <script type="text/javascript" src="js/dojo/dojo.xd.js" data-dojo-config="async: true"></script>
 <script type="text/javascript">
    dojo.require("dojo.parser");
    dojo.require("dijit.form.Form");
    dojo.require("dijit.form.Button");
    dojo.require("dijit.form.ValidationTextBox");
    dojo.require("dijit.form.DateTextBox");
  </script>
</head>
<body class="tundra">
  <table style="border: 1px solid black;">
    <tr>
      <td>Name:</td>
      <td><input type="text" id="name" name="name"
                 data-dojo-type="dijit.form.ValidationTextBox" /></td>
    </tr>
    <tr>
      <td>Date of birth:</td>
      <td><input type="text" id="dob" name="dob"
                 data-dojo-type="dijit.form.DateTextBox" /></td>
    </tr>
  </table>
  <input type="button" name="submitButton" value="Submit" />
</body>
</html>
2

There are 2 best solutions below

1
On

As of Dojo 1.8, the parser accepts a Module ID (MID) for the type. Previously it accepted the declared class name of the object. It also accepts anything that is declared in the global scope

So

<input type="text" id="name" name="name"
        data-dojo-type="dijit.form.ValidationTextBox" />

should be

<input type="text" id="name" name="name"
        data-dojo-type="dijit/form/ValidationTextBox" />

http://dojotoolkit.org/reference-guide/1.9/dojo/parser.html#id8

0
On

frameworks answer is deprecated legacy code from before dojo 1.6 !!!

  1. read the migration guide or this tutorial

  2. In the original code

IF YOUR dojo IS 1.9 (as you commented), IT IS NOT LOADED

Prior to Dojo 1.7, the cross-domain Dojo loader script was named dojo.xd.js

REMOVE the .xd !

Add

parseOnLoad:    true

to dojoConfig (to be sure)

and change your dojo.require syntax to the correct one (see tutorial) :

require(["dojo/parser","dijit/form/Form", "ETC..."], function(){})