javascript - Trying to make a dojo widget that will create a form -


i wanted make place data-dojo-type="js/widget/sauploadform" upload widget generate form there. not sure wrong right no form generated on page.

<html> <head> <title>upload</title> <script>     dojoconfig = {         async : true,         parseonload : false     } </script> <script src="js/dojo/dojo.js"></script> </head> <body> <div>     <h1 align="center">upload</h1>     <br />     <div data-dojo-type="js/widget/sauploadform"></div> </div> </body> </html> 

my widget file: sauploadform.js

define(["dojo/_base/declare", "dojo/dom-construct", "dojo/parser", "dijit/_widgetbase", "dijit/_templatedmixin"],     function(declare, domconstruct, parser, ready, _widgetbase, _templatedmixin) {         decalre("sauploadform", [_widgetbase, _templatedmixin], {             formstring: '<form method="post" enctype="multipart/form-data" action="/webapp/upload">' +             '<table>' +                  '<tr>' +                      '<td>file:</td>' +                      '<td><input type="file" name="file" value="browse" accept=".sub" /></td>' +                  '</tr><tr>' +                      '<td colspan="2"><button type="submit">upload</button></td>' +                  '</tr>' +              '</table></form>',               buildrendering: function() {                 this.domnode.innerhtml = formstring;             }         });          ready(function() {             parser.parse();         }); }); 

this located @ js/widget/

well, there many wrong thing here...

  • there typo: decalre instead of declare
  • you should use templatestring , not custom formstring
  • you have require js/widget/sauploadform if want parser know it
  • you declare ready don't require it
  • the result of declare should returned

something should work:
(note: snippets cannot work because code needs put widget separate file)

//this goes js/widget/sauploadform.js  define(["dojo/_base/declare", "dojo/dom-construct", "dijit/_widgetbase", "dijit/_templatedmixin"],      function(declare, domconstruct, _widgetbase, _templatedmixin) {         return declare("js/widget/sauploadform", [_widgetbase, _templatedmixin], {              templatestring: '<form method="post" enctype="multipart/form-data" action="/webapp/upload">' +              '<table>' +                   '<tr>' +                       '<td>file:</td>' +                       '<td><input type="file" name="file" value="browse" accept=".sub" /></td>' +                   '</tr><tr>' +                       '<td colspan="2"><button type="submit">upload</button></td>' +                   '</tr>' +               '</table></form>'          });  });    //this goes index.html file  require(["dojo/parser", "dojo/domready!", "js/widget/sauploadform"], function(parser) {     parser.parse();  });
<script>      dojoconfig = {          async : true,          parseonload : false      }  </script>  <script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>  <div>      <div data-dojo-type="js/widget/sauploadform"></div>  </div>


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -