[Dojo-interest] best practice for doing a post in a custom widget?

computerbum robasc33 at yahoo.com
Wed Jan 29 12:22:22 EST 2014


Hello all,

So I built a widget named "Login" using the new amd loader. I am trying to
figure out the best way validate a user by sending the data to the server.
What is the best way to handle this situation?

//Login.js
define([ 
         "dojo/_base/declare",
         "dojo/_base/lang",
         "dojo/_base/array",
         "dojo/on",
		 "dojo/dom-construct",
		 "dijit/_WidgetBase",
		 "dijit/_TemplatedMixin",
		 "dijit/_WidgetsInTemplateMixin",
		 "dojo/text!./templates/Login.html",
		 "dijit/form/TextBox",
		 "dijit/form/Button"
        ],
		 function(declare, lang, arrayUtil, on, domConstruct, _WidgetBase,
				_TemplatedMixin, _WidgetsInTemplateMixin, template) {

			return declare([ _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin ],
{

				templateString : template,

				title : "Please Login",

				postMixInProperties : function() {

				},

				postCreate : function() {

					this.inherited(arguments);
                    
                    this.own(
	                    on(this.submitButton, "click", lang.hitch(this,
"_validateUser"))
                    );

				},

                _validateUser: function() {

                        // do a post and on return validation object in
order to allow access 
                     
                }

			});
		});


// TEMPLATE Login.html
<div class="Login">
   
   <div><${title}</div>

   <label for="userName">UserName: </label>
   <input data-dojo-type="dijit/form/TextBox" type="text" 
          data-dojo-attach-point="userName" >
          
   <label for="password">Password: </label>
   <input data-dojo-type="dijit/form/TextBox" type="password" 
          data-dojo-attach-point="password" >

   <button data-dojo-type="dijit/form/Button" type="button"
           data-dojo-attach-point="submitButton">Submit</button>
</div>

// index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Login</title>
<link rel="stylesheet" href="custom/resources/css/Login.css">
</head>
<body class="claro">
  
  <div id="loginNode"></div>

  
  
</body>
</html>



--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/best-practice-for-doing-a-post-in-a-custom-widget-tp4000897.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.


More information about the Dojo-interest mailing list