Fwd: pwCheck function in PasswordValidator

classic Classic list List threaded Threaded
36 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Fwd: pwCheck function in PasswordValidator

sg3235


Begin forwarded message:

From: Stephen Gevers <[hidden email]>
Subject: Re: [Dojo-interest] pwCheck function in PasswordValidator
Date: March 4, 2015 at 1:51:11 PM CST

I’m not sure what you mean by “main require” and “main javascript file”.  Is the main require in a script tag in HTML?  Is the function validateUserEntered embedded inside a require of it’s own?  That would explain your undefined function as validateUserEntered’s scope would be the require inside your main javascript file and not accessible to anything outside.  But even if you solve that, you still have issues in the code below.  In the “then” function you supply for validateUserEntered, where do you expect the “return true” to go?  Also, since your button is a widget, I don’t think you want dom.byId.  I believe you want on(registry.byId().domNode, …).  Or registry.byId().on(…).

The problem I think you are having is that you are trying to use AMD without creating any modules.  If I’m correct in the layout (and what you mean by main require and main javascript), you need to think of it this way: You have two different require invocations with two different callbacks.  The stuff that’s declared inside one of those call backs is not accessible to the other one without some trickery.  And that trickery is also considered bad practice.

So you need to restructure a bit.  Your main javascript file needs to have a “define” rather than a “require”.  By using “define” you can expose things in your main javascript file to things inside other “require” functions.  I’m going to assume you are loading your main javascript file using a script tag in the same way you are loading dojo itself and that you are loading it from the URL /js/main.js  The first thing we want to do is to have dojo load your file itself, rather than you doing it through the script tag.  To do so, we have to consider it to be part of a “package”.  Before you load dojo, you should create a script tag that contains the following (not in a require):
var dojoConfig = {
packages: [ { name: ‘myApp’, location: ‘/js’ } ];
];

In your main require, add a dependency for "myApp/main”.  This will cause your main javascript file to be loaded and processed.  You will also need to add a corresponding argument to the require call back function.

In your main.js, change the “require” to “define”.  The parameters are the same: an array of dependencies and a callback function with an argument list that matches the array.  The only difference is that you will be returning something.  That something will be mapped to the parameter you added to your main require.  So it will look something like this:

define ([…], function (…) {
return {
validateUserEntered: function () {
//function body
},

// other functions you want to use outside this function
};
});

In your main require you would have

require ([…, ‘myApp/main’], function (…, main) {
parser.parse();
on(registry.byId(‘accountInfo’).domNode, ‘click’, function (evt) {
main.validateUserEntered().then(function (data) {
console.log(“valid user”);
});
});
});

On Mar 4, 2015, at 1:02 PM, Harry Devine <[hidden email]> wrote:

Sorry, still now working.  I'm defining my button as follows:

<button data-dojo-type="dijit/form/Button" type="button" id="accountInfo">Show Account Info</button>

In my main require, I have:

parser.parse();
on(dom.byId("accountInfo"), 'click', function(evt) {
  validateUserEntered().then(function(data) {
    return true;
  });
});

And in my main javascript file, I have validateUserEntered as follows:

function validateUserEntered() {
  var dfd = new Deferred();
  if (!registry.byId("username").get("value")) {
    dom.byId("ldapResult".innerHTML = "User name not specified!";
    dfd.reject("fail");
  }
  else {
    dfd.resolve("success");
  }
}

The error I get is:  Uncaught ReferenceError: validateUserEntered is not defined.

Obviously I'm missing something basic.  I'm trying to make my main javascript file have requires for all dojo modules I'll need in there, and then have the functions defined within the require/function blocks.  Like I mentioned earlier, I always had these types of errors doing it this way but having require/function in each sub function always worked, but according to Karl, this way is wrong.  So how do I fix this?

Thanks,
Harry




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

Harry Devine
OK, so I'm trudging through this slowly, and I can't get the function to work when I click the button.  I get Uncaught TypeError: undefined is not a function.  Here's my utils.js file now:

define("utils", [
  "dijit/registry",
  "dojo/Deferred"
], function(registry, Deferred) {
  return {
    validateUserEntered: function() {
      var dfd = new Deferred();
      if (!registry.byId("username").get("value")) {
        console.log("User name not entered!");
        dfd.reject("fail");
      }
      else {
        console.log("User name entered");
        dfd.resolve("success");
      }
      return true;
    }
  }
});

In my index.php:

<script>
  var dojoConfig = {
    tlmSiblingofDojo: false,
    packages: [
      {name: "ldapUtils", location: "/ldap/accountinfo"}
    ]
  };
</script>

require(...., "ldapUtils/utils")

then how I handle the button click:

on(dom.byId("accountInfo"), 'click', function(evt) {
  utils.validateUserEntered().then(function(data){                         <-------  this is where the error above is flagged
    console.log(data);
  });
});

Any ideas?
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Wednesday, March 4, 2015 2:55:41 PM
Subject: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator



Begin forwarded message:

From: Stephen Gevers <[hidden email]>
Subject: Re: [Dojo-interest] pwCheck function in PasswordValidator
Date: March 4, 2015 at 1:51:11 PM CST

I’m not sure what you mean by “main require” and “main javascript file”.  Is the main require in a script tag in HTML?  Is the function validateUserEntered embedded inside a require of it’s own?  That would explain your undefined function as validateUserEntered’s scope would be the require inside your main javascript file and not accessible to anything outside.  But even if you solve that, you still have issues in the code below.  In the “then” function you supply for validateUserEntered, where do you expect the “return true” to go?  Also, since your button is a widget, I don’t think you want dom.byId.  I believe you want on(registry.byId().domNode, …).  Or registry.byId().on(…).

The problem I think you are having is that you are trying to use AMD without creating any modules.  If I’m correct in the layout (and what you mean by main require and main javascript), you need to think of it this way: You have two different require invocations with two different callbacks.  The stuff that’s declared inside one of those call backs is not accessible to the other one without some trickery.  And that trickery is also considered bad practice.

So you need to restructure a bit.  Your main javascript file needs to have a “define” rather than a “require”.  By using “define” you can expose things in your main javascript file to things inside other “require” functions.  I’m going to assume you are loading your main javascript file using a script tag in the same way you are loading dojo itself and that you are loading it from the URL /js/main.js  The first thing we want to do is to have dojo load your file itself, rather than you doing it through the script tag.  To do so, we have to consider it to be part of a “package”.  Before you load dojo, you should create a script tag that contains the following (not in a require):
var dojoConfig = {
packages: [ { name: ‘myApp’, location: ‘/js’ } ];
];

In your main require, add a dependency for "myApp/main”.  This will cause your main javascript file to be loaded and processed.  You will also need to add a corresponding argument to the require call back function.

In your main.js, change the “require” to “define”.  The parameters are the same: an array of dependencies and a callback function with an argument list that matches the array.  The only difference is that you will be returning something.  That something will be mapped to the parameter you added to your main require.  So it will look something like this:

define ([…], function (…) {
return {
validateUserEntered: function () {
//function body
},

// other functions you want to use outside this function
};
});

In your main require you would have

require ([…, ‘myApp/main’], function (…, main) {
parser.parse();
on(registry.byId(‘accountInfo’).domNode, ‘click’, function (evt) {
main.validateUserEntered().then(function (data) {
console.log(“valid user”);
});
});
});

On Mar 4, 2015, at 1:02 PM, Harry Devine <[hidden email]> wrote:

Sorry, still now working.  I'm defining my button as follows:

<button data-dojo-type="dijit/form/Button" type="button" id="accountInfo">Show Account Info</button>

In my main require, I have:

parser.parse();
on(dom.byId("accountInfo"), 'click', function(evt) {
  validateUserEntered().then(function(data) {
    return true;
  });
});

And in my main javascript file, I have validateUserEntered as follows:

function validateUserEntered() {
  var dfd = new Deferred();
  if (!registry.byId("username").get("value")) {
    dom.byId("ldapResult".innerHTML = "User name not specified!";
    dfd.reject("fail");
  }
  else {
    dfd.resolve("success");
  }
}

The error I get is:  Uncaught ReferenceError: validateUserEntered is not defined.

Obviously I'm missing something basic.  I'm trying to make my main javascript file have requires for all dojo modules I'll need in there, and then have the functions defined within the require/function blocks.  Like I mentioned earlier, I always had these types of errors doing it this way but having require/function in each sub function always worked, but according to Karl, this way is wrong.  So how do I fix this?

Thanks,
Harry




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

sg3235
The first thing I see is that you supplied the string parameter to define.  You are supposed to let the environment determine that with the location of the file.  Your file should be located at the url /ldap/accountinfo/utils.js.
The module is "ldapUtils/utils", not just utils as you have specified to define.

Steve
On Mar 9, 2015, at 7:47 AM, Harry Devine <[hidden email]> wrote:

OK, so I'm trudging through this slowly, and I can't get the function to work when I click the button.  I get Uncaught TypeError: undefined is not a function.  Here's my utils.js file now:

define("utils", [
  "dijit/registry",
  "dojo/Deferred"
], function(registry, Deferred) {
  return {
    validateUserEntered: function() {
      var dfd = new Deferred();
      if (!registry.byId("username").get("value")) {
        console.log("User name not entered!");
        dfd.reject("fail");
      }
      else {
        console.log("User name entered");
        dfd.resolve("success");
      }
      return true;
    }
  }
});

In my index.php:

<script>
  var dojoConfig = {
    tlmSiblingofDojo: false,
    packages: [
      {name: "ldapUtils", location: "/ldap/accountinfo"}
    ]
  };
</script>

require(...., "ldapUtils/utils")

then how I handle the button click:

on(dom.byId("accountInfo"), 'click', function(evt) {
  utils.validateUserEntered().then(function(data){                         <-------  this is where the error above is flagged
    console.log(data);
  });
});

Any ideas?
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Wednesday, March 4, 2015 2:55:41 PM
Subject: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator



Begin forwarded message:

From: Stephen Gevers <[hidden email]>
Subject: Re: [Dojo-interest] pwCheck function in PasswordValidator
Date: March 4, 2015 at 1:51:11 PM CST

I’m not sure what you mean by “main require” and “main javascript file”.  Is the main require in a script tag in HTML?  Is the function validateUserEntered embedded inside a require of it’s own?  That would explain your undefined function as validateUserEntered’s scope would be the require inside your main javascript file and not accessible to anything outside.  But even if you solve that, you still have issues in the code below.  In the “then” function you supply for validateUserEntered, where do you expect the “return true” to go?  Also, since your button is a widget, I don’t think you want dom.byId.  I believe you want on(registry.byId().domNode, …).  Or registry.byId().on(…).

The problem I think you are having is that you are trying to use AMD without creating any modules.  If I’m correct in the layout (and what you mean by main require and main javascript), you need to think of it this way: You have two different require invocations with two different callbacks.  The stuff that’s declared inside one of those call backs is not accessible to the other one without some trickery.  And that trickery is also considered bad practice.

So you need to restructure a bit.  Your main javascript file needs to have a “define” rather than a “require”.  By using “define” you can expose things in your main javascript file to things inside other “require” functions.  I’m going to assume you are loading your main javascript file using a script tag in the same way you are loading dojo itself and that you are loading it from the URL /js/main.js  The first thing we want to do is to have dojo load your file itself, rather than you doing it through the script tag.  To do so, we have to consider it to be part of a “package”.  Before you load dojo, you should create a script tag that contains the following (not in a require):
var dojoConfig = {
packages: [ { name: ‘myApp’, location: ‘/js’ } ];
];

In your main require, add a dependency for "myApp/main”.  This will cause your main javascript file to be loaded and processed.  You will also need to add a corresponding argument to the require call back function.

In your main.js, change the “require” to “define”.  The parameters are the same: an array of dependencies and a callback function with an argument list that matches the array.  The only difference is that you will be returning something.  That something will be mapped to the parameter you added to your main require.  So it will look something like this:

define ([…], function (…) {
return {
validateUserEntered: function () {
//function body
},

// other functions you want to use outside this function
};
});

In your main require you would have

require ([…, ‘myApp/main’], function (…, main) {
parser.parse();
on(registry.byId(‘accountInfo’).domNode, ‘click’, function (evt) {
main.validateUserEntered().then(function (data) {
console.log(“valid user”);
});
});
});

On Mar 4, 2015, at 1:02 PM, Harry Devine <[hidden email]> wrote:

Sorry, still now working.  I'm defining my button as follows:

<button data-dojo-type="dijit/form/Button" type="button" id="accountInfo">Show Account Info</button>

In my main require, I have:

parser.parse();
on(dom.byId("accountInfo"), 'click', function(evt) {
  validateUserEntered().then(function(data) {
    return true;
  });
});

And in my main javascript file, I have validateUserEntered as follows:

function validateUserEntered() {
  var dfd = new Deferred();
  if (!registry.byId("username").get("value")) {
    dom.byId("ldapResult".innerHTML = "User name not specified!";
    dfd.reject("fail");
  }
  else {
    dfd.resolve("success");
  }
}

The error I get is:  Uncaught ReferenceError: validateUserEntered is not defined.

Obviously I'm missing something basic.  I'm trying to make my main javascript file have requires for all dojo modules I'll need in there, and then have the functions defined within the require/function blocks.  Like I mentioned earlier, I always had these types of errors doing it this way but having require/function in each sub function always worked, but according to Karl, this way is wrong.  So how do I fix this?

Thanks,
Harry




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

Harry Devine
OK, I fixed that (didn't understand what having that string there would do).  But I get the same error, only this time its on the line that says dfd.resolve. The error is Uncaught TypeError: undefined is not a function.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 9:16:58 AM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

The first thing I see is that you supplied the string parameter to define.  You are supposed to let the environment determine that with the location of the file.  Your file should be located at the url /ldap/accountinfo/utils.js.
The module is "ldapUtils/utils", not just utils as you have specified to define.

Steve
On Mar 9, 2015, at 7:47 AM, Harry Devine <[hidden email]> wrote:

OK, so I'm trudging through this slowly, and I can't get the function to work when I click the button.  I get Uncaught TypeError: undefined is not a function.  Here's my utils.js file now:

define("utils", [
  "dijit/registry",
  "dojo/Deferred"
], function(registry, Deferred) {
  return {
    validateUserEntered: function() {
      var dfd = new Deferred();
      if (!registry.byId("username").get("value")) {
        console.log("User name not entered!");
        dfd.reject("fail");
      }
      else {
        console.log("User name entered");
        dfd.resolve("success");
      }
      return true;
    }
  }
});

In my index.php:

<script>
  var dojoConfig = {
    tlmSiblingofDojo: false,
    packages: [
      {name: "ldapUtils", location: "/ldap/accountinfo"}
    ]
  };
</script>

require(...., "ldapUtils/utils")

then how I handle the button click:

on(dom.byId("accountInfo"), 'click', function(evt) {
  utils.validateUserEntered().then(function(data){                         <-------  this is where the error above is flagged
    console.log(data);
  });
});

Any ideas?
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Wednesday, March 4, 2015 2:55:41 PM
Subject: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator



Begin forwarded message:

From: Stephen Gevers <[hidden email]>
Subject: Re: [Dojo-interest] pwCheck function in PasswordValidator
Date: March 4, 2015 at 1:51:11 PM CST

I’m not sure what you mean by “main require” and “main javascript file”.  Is the main require in a script tag in HTML?  Is the function validateUserEntered embedded inside a require of it’s own?  That would explain your undefined function as validateUserEntered’s scope would be the require inside your main javascript file and not accessible to anything outside.  But even if you solve that, you still have issues in the code below.  In the “then” function you supply for validateUserEntered, where do you expect the “return true” to go?  Also, since your button is a widget, I don’t think you want dom.byId.  I believe you want on(registry.byId().domNode, …).  Or registry.byId().on(…).

The problem I think you are having is that you are trying to use AMD without creating any modules.  If I’m correct in the layout (and what you mean by main require and main javascript), you need to think of it this way: You have two different require invocations with two different callbacks.  The stuff that’s declared inside one of those call backs is not accessible to the other one without some trickery.  And that trickery is also considered bad practice.

So you need to restructure a bit.  Your main javascript file needs to have a “define” rather than a “require”.  By using “define” you can expose things in your main javascript file to things inside other “require” functions.  I’m going to assume you are loading your main javascript file using a script tag in the same way you are loading dojo itself and that you are loading it from the URL /js/main.js  The first thing we want to do is to have dojo load your file itself, rather than you doing it through the script tag.  To do so, we have to consider it to be part of a “package”.  Before you load dojo, you should create a script tag that contains the following (not in a require):
var dojoConfig = {
packages: [ { name: ‘myApp’, location: ‘/js’ } ];
];

In your main require, add a dependency for "myApp/main”.  This will cause your main javascript file to be loaded and processed.  You will also need to add a corresponding argument to the require call back function.

In your main.js, change the “require” to “define”.  The parameters are the same: an array of dependencies and a callback function with an argument list that matches the array.  The only difference is that you will be returning something.  That something will be mapped to the parameter you added to your main require.  So it will look something like this:

define ([…], function (…) {
return {
validateUserEntered: function () {
//function body
},

// other functions you want to use outside this function
};
});

In your main require you would have

require ([…, ‘myApp/main’], function (…, main) {
parser.parse();
on(registry.byId(‘accountInfo’).domNode, ‘click’, function (evt) {
main.validateUserEntered().then(function (data) {
console.log(“valid user”);
});
});
});

On Mar 4, 2015, at 1:02 PM, Harry Devine <[hidden email]> wrote:

Sorry, still now working.  I'm defining my button as follows:

<button data-dojo-type="dijit/form/Button" type="button" id="accountInfo">Show Account Info</button>

In my main require, I have:

parser.parse();
on(dom.byId("accountInfo"), 'click', function(evt) {
  validateUserEntered().then(function(data) {
    return true;
  });
});

And in my main javascript file, I have validateUserEntered as follows:

function validateUserEntered() {
  var dfd = new Deferred();
  if (!registry.byId("username").get("value")) {
    dom.byId("ldapResult".innerHTML = "User name not specified!";
    dfd.reject("fail");
  }
  else {
    dfd.resolve("success");
  }
}

The error I get is:  Uncaught ReferenceError: validateUserEntered is not defined.

Obviously I'm missing something basic.  I'm trying to make my main javascript file have requires for all dojo modules I'll need in there, and then have the functions defined within the require/function blocks.  Like I mentioned earlier, I always had these types of errors doing it this way but having require/function in each sub function always worked, but according to Karl, this way is wrong.  So how do I fix this?

Thanks,
Harry




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

sg3235
I didn’t notice this the first time, but your validateUserEntered function should return dfd, not true.  The return from validateUserEntered is the context for the “then” function.  I don’t think that explains the “undefined is not a function”, though.  Are you getting the “User name entered” output to the console right before the dd.resolve?


On Mar 9, 2015, at 11:50 AM, Harry Devine <[hidden email]> wrote:

OK, I fixed that (didn't understand what having that string there would do).  But I get the same error, only this time its on the line that says dfd.resolve. The error is Uncaught TypeError: undefined is not a function.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 9:16:58 AM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

The first thing I see is that you supplied the string parameter to define.  You are supposed to let the environment determine that with the location of the file.  Your file should be located at the url /ldap/accountinfo/utils.js.
The module is "ldapUtils/utils", not just utils as you have specified to define.

Steve
On Mar 9, 2015, at 7:47 AM, Harry Devine <[hidden email]> wrote:

OK, so I'm trudging through this slowly, and I can't get the function to work when I click the button.  I get Uncaught TypeError: undefined is not a function.  Here's my utils.js file now:

define("utils", [
  "dijit/registry",
  "dojo/Deferred"
], function(registry, Deferred) {
  return {
    validateUserEntered: function() {
      var dfd = new Deferred();
      if (!registry.byId("username").get("value")) {
        console.log("User name not entered!");
        dfd.reject("fail");
      }
      else {
        console.log("User name entered");
        dfd.resolve("success");
      }
      return true;
    }
  }
});

In my index.php:

<script>
  var dojoConfig = {
    tlmSiblingofDojo: false,
    packages: [
      {name: "ldapUtils", location: "/ldap/accountinfo"}
    ]
  };
</script>

require(...., "ldapUtils/utils")

then how I handle the button click:

on(dom.byId("accountInfo"), 'click', function(evt) {
  utils.validateUserEntered().then(function(data){                         <-------  this is where the error above is flagged
    console.log(data);
  });
});

Any ideas?
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Wednesday, March 4, 2015 2:55:41 PM
Subject: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator



Begin forwarded message:

From: Stephen Gevers <[hidden email]>
Subject: Re: [Dojo-interest] pwCheck function in PasswordValidator
Date: March 4, 2015 at 1:51:11 PM CST

I’m not sure what you mean by “main require” and “main javascript file”.  Is the main require in a script tag in HTML?  Is the function validateUserEntered embedded inside a require of it’s own?  That would explain your undefined function as validateUserEntered’s scope would be the require inside your main javascript file and not accessible to anything outside.  But even if you solve that, you still have issues in the code below.  In the “then” function you supply for validateUserEntered, where do you expect the “return true” to go?  Also, since your button is a widget, I don’t think you want dom.byId.  I believe you want on(registry.byId().domNode, …).  Or registry.byId().on(…).

The problem I think you are having is that you are trying to use AMD without creating any modules.  If I’m correct in the layout (and what you mean by main require and main javascript), you need to think of it this way: You have two different require invocations with two different callbacks.  The stuff that’s declared inside one of those call backs is not accessible to the other one without some trickery.  And that trickery is also considered bad practice.

So you need to restructure a bit.  Your main javascript file needs to have a “define” rather than a “require”.  By using “define” you can expose things in your main javascript file to things inside other “require” functions.  I’m going to assume you are loading your main javascript file using a script tag in the same way you are loading dojo itself and that you are loading it from the URL /js/main.js  The first thing we want to do is to have dojo load your file itself, rather than you doing it through the script tag.  To do so, we have to consider it to be part of a “package”.  Before you load dojo, you should create a script tag that contains the following (not in a require):
var dojoConfig = {
packages: [ { name: ‘myApp’, location: ‘/js’ } ];
];

In your main require, add a dependency for "myApp/main”.  This will cause your main javascript file to be loaded and processed.  You will also need to add a corresponding argument to the require call back function.

In your main.js, change the “require” to “define”.  The parameters are the same: an array of dependencies and a callback function with an argument list that matches the array.  The only difference is that you will be returning something.  That something will be mapped to the parameter you added to your main require.  So it will look something like this:

define ([…], function (…) {
return {
validateUserEntered: function () {
//function body
},

// other functions you want to use outside this function
};
});

In your main require you would have

require ([…, ‘myApp/main’], function (…, main) {
parser.parse();
on(registry.byId(‘accountInfo’).domNode, ‘click’, function (evt) {
main.validateUserEntered().then(function (data) {
console.log(“valid user”);
});
});
});

On Mar 4, 2015, at 1:02 PM, Harry Devine <[hidden email]> wrote:

Sorry, still now working.  I'm defining my button as follows:

<button data-dojo-type="dijit/form/Button" type="button" id="accountInfo">Show Account Info</button>

In my main require, I have:

parser.parse();
on(dom.byId("accountInfo"), 'click', function(evt) {
  validateUserEntered().then(function(data) {
    return true;
  });
});

And in my main javascript file, I have validateUserEntered as follows:

function validateUserEntered() {
  var dfd = new Deferred();
  if (!registry.byId("username").get("value")) {
    dom.byId("ldapResult".innerHTML = "User name not specified!";
    dfd.reject("fail");
  }
  else {
    dfd.resolve("success");
  }
}

The error I get is:  Uncaught ReferenceError: validateUserEntered is not defined.

Obviously I'm missing something basic.  I'm trying to make my main javascript file have requires for all dojo modules I'll need in there, and then have the functions defined within the require/function blocks.  Like I mentioned earlier, I always had these types of errors doing it this way but having require/function in each sub function always worked, but according to Karl, this way is wrong.  So how do I fix this?

Thanks,
Harry




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

Harry Devine
Yes I am.  Sorry if I seem dense over this.  This whole Deferred thing is brand new to me.  Learning as I go.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:05:49 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

I didn’t notice this the first time, but your validateUserEntered function should return dfd, not true.  The return from validateUserEntered is the context for the “then” function.  I don’t think that explains the “undefined is not a function”, though.  Are you getting the “User name entered” output to the console right before the dd.resolve?


On Mar 9, 2015, at 11:50 AM, Harry Devine <[hidden email]> wrote:

OK, I fixed that (didn't understand what having that string there would do).  But I get the same error, only this time its on the line that says dfd.resolve. The error is Uncaught TypeError: undefined is not a function.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 9:16:58 AM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

The first thing I see is that you supplied the string parameter to define.  You are supposed to let the environment determine that with the location of the file.  Your file should be located at the url /ldap/accountinfo/utils.js.
The module is "ldapUtils/utils", not just utils as you have specified to define.

Steve
On Mar 9, 2015, at 7:47 AM, Harry Devine <[hidden email]> wrote:

OK, so I'm trudging through this slowly, and I can't get the function to work when I click the button.  I get Uncaught TypeError: undefined is not a function.  Here's my utils.js file now:

define("utils", [
  "dijit/registry",
  "dojo/Deferred"
], function(registry, Deferred) {
  return {
    validateUserEntered: function() {
      var dfd = new Deferred();
      if (!registry.byId("username").get("value")) {
        console.log("User name not entered!");
        dfd.reject("fail");
      }
      else {
        console.log("User name entered");
        dfd.resolve("success");
      }
      return true;
    }
  }
});

In my index.php:

<script>
  var dojoConfig = {
    tlmSiblingofDojo: false,
    packages: [
      {name: "ldapUtils", location: "/ldap/accountinfo"}
    ]
  };
</script>

require(...., "ldapUtils/utils")

then how I handle the button click:

on(dom.byId("accountInfo"), 'click', function(evt) {
  utils.validateUserEntered().then(function(data){                         <-------  this is where the error above is flagged
    console.log(data);
  });
});

Any ideas?
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Wednesday, March 4, 2015 2:55:41 PM
Subject: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator



Begin forwarded message:

From: Stephen Gevers <[hidden email]>
Subject: Re: [Dojo-interest] pwCheck function in PasswordValidator
Date: March 4, 2015 at 1:51:11 PM CST

I’m not sure what you mean by “main require” and “main javascript file”.  Is the main require in a script tag in HTML?  Is the function validateUserEntered embedded inside a require of it’s own?  That would explain your undefined function as validateUserEntered’s scope would be the require inside your main javascript file and not accessible to anything outside.  But even if you solve that, you still have issues in the code below.  In the “then” function you supply for validateUserEntered, where do you expect the “return true” to go?  Also, since your button is a widget, I don’t think you want dom.byId.  I believe you want on(registry.byId().domNode, …).  Or registry.byId().on(…).

The problem I think you are having is that you are trying to use AMD without creating any modules.  If I’m correct in the layout (and what you mean by main require and main javascript), you need to think of it this way: You have two different require invocations with two different callbacks.  The stuff that’s declared inside one of those call backs is not accessible to the other one without some trickery.  And that trickery is also considered bad practice.

So you need to restructure a bit.  Your main javascript file needs to have a “define” rather than a “require”.  By using “define” you can expose things in your main javascript file to things inside other “require” functions.  I’m going to assume you are loading your main javascript file using a script tag in the same way you are loading dojo itself and that you are loading it from the URL /js/main.js  The first thing we want to do is to have dojo load your file itself, rather than you doing it through the script tag.  To do so, we have to consider it to be part of a “package”.  Before you load dojo, you should create a script tag that contains the following (not in a require):
var dojoConfig = {
packages: [ { name: ‘myApp’, location: ‘/js’ } ];
];

In your main require, add a dependency for "myApp/main”.  This will cause your main javascript file to be loaded and processed.  You will also need to add a corresponding argument to the require call back function.

In your main.js, change the “require” to “define”.  The parameters are the same: an array of dependencies and a callback function with an argument list that matches the array.  The only difference is that you will be returning something.  That something will be mapped to the parameter you added to your main require.  So it will look something like this:

define ([…], function (…) {
return {
validateUserEntered: function () {
//function body
},

// other functions you want to use outside this function
};
});

In your main require you would have

require ([…, ‘myApp/main’], function (…, main) {
parser.parse();
on(registry.byId(‘accountInfo’).domNode, ‘click’, function (evt) {
main.validateUserEntered().then(function (data) {
console.log(“valid user”);
});
});
});

On Mar 4, 2015, at 1:02 PM, Harry Devine <[hidden email]> wrote:

Sorry, still now working.  I'm defining my button as follows:

<button data-dojo-type="dijit/form/Button" type="button" id="accountInfo">Show Account Info</button>

In my main require, I have:

parser.parse();
on(dom.byId("accountInfo"), 'click', function(evt) {
  validateUserEntered().then(function(data) {
    return true;
  });
});

And in my main javascript file, I have validateUserEntered as follows:

function validateUserEntered() {
  var dfd = new Deferred();
  if (!registry.byId("username").get("value")) {
    dom.byId("ldapResult".innerHTML = "User name not specified!";
    dfd.reject("fail");
  }
  else {
    dfd.resolve("success");
  }
}

The error I get is:  Uncaught ReferenceError: validateUserEntered is not defined.

Obviously I'm missing something basic.  I'm trying to make my main javascript file have requires for all dojo modules I'll need in there, and then have the functions defined within the require/function blocks.  Like I mentioned earlier, I always had these types of errors doing it this way but having require/function in each sub function always worked, but according to Karl, this way is wrong.  So how do I fix this?

Thanks,
Harry




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

sg3235
No problems.  I’m not judging…just trying to help.  I’m trying to give reasons for what’s wrong, not just telling you what to change so that, hopefully, it will be easier for you next time.  Did you make the change to have validateUserEntered return dfd?  If so, try putting a console.log(dfd) right above the dfd.resolve call and let me know what it logs for the object.  It should show an object that has a resolve function on it.

Steve

On Mar 9, 2015, at 12:16 PM, Harry Devine <[hidden email]> wrote:

Yes I am.  Sorry if I seem dense over this.  This whole Deferred thing is brand new to me.  Learning as I go.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:05:49 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

I didn’t notice this the first time, but your validateUserEntered function should return dfd, not true.  The return from validateUserEntered is the context for the “then” function.  I don’t think that explains the “undefined is not a function”, though.  Are you getting the “User name entered” output to the console right before the dd.resolve?


On Mar 9, 2015, at 11:50 AM, Harry Devine <[hidden email]> wrote:

OK, I fixed that (didn't understand what having that string there would do).  But I get the same error, only this time its on the line that says dfd.resolve. The error is Uncaught TypeError: undefined is not a function.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 9:16:58 AM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

The first thing I see is that you supplied the string parameter to define.  You are supposed to let the environment determine that with the location of the file.  Your file should be located at the url /ldap/accountinfo/utils.js.
The module is "ldapUtils/utils", not just utils as you have specified to define.

Steve
On Mar 9, 2015, at 7:47 AM, Harry Devine <[hidden email]> wrote:

OK, so I'm trudging through this slowly, and I can't get the function to work when I click the button.  I get Uncaught TypeError: undefined is not a function.  Here's my utils.js file now:

define("utils", [
  "dijit/registry",
  "dojo/Deferred"
], function(registry, Deferred) {
  return {
    validateUserEntered: function() {
      var dfd = new Deferred();
      if (!registry.byId("username").get("value")) {
        console.log("User name not entered!");
        dfd.reject("fail");
      }
      else {
        console.log("User name entered");
        dfd.resolve("success");
      }
      return true;
    }
  }
});

In my index.php:

<script>
  var dojoConfig = {
    tlmSiblingofDojo: false,
    packages: [
      {name: "ldapUtils", location: "/ldap/accountinfo"}
    ]
  };
</script>

require(...., "ldapUtils/utils")

then how I handle the button click:

on(dom.byId("accountInfo"), 'click', function(evt) {
  utils.validateUserEntered().then(function(data){                         <-------  this is where the error above is flagged
    console.log(data);
  });
});

Any ideas?
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Wednesday, March 4, 2015 2:55:41 PM
Subject: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator



Begin forwarded message:

From: Stephen Gevers <[hidden email]>
Subject: Re: [Dojo-interest] pwCheck function in PasswordValidator
Date: March 4, 2015 at 1:51:11 PM CST

I’m not sure what you mean by “main require” and “main javascript file”.  Is the main require in a script tag in HTML?  Is the function validateUserEntered embedded inside a require of it’s own?  That would explain your undefined function as validateUserEntered’s scope would be the require inside your main javascript file and not accessible to anything outside.  But even if you solve that, you still have issues in the code below.  In the “then” function you supply for validateUserEntered, where do you expect the “return true” to go?  Also, since your button is a widget, I don’t think you want dom.byId.  I believe you want on(registry.byId().domNode, …).  Or registry.byId().on(…).

The problem I think you are having is that you are trying to use AMD without creating any modules.  If I’m correct in the layout (and what you mean by main require and main javascript), you need to think of it this way: You have two different require invocations with two different callbacks.  The stuff that’s declared inside one of those call backs is not accessible to the other one without some trickery.  And that trickery is also considered bad practice.

So you need to restructure a bit.  Your main javascript file needs to have a “define” rather than a “require”.  By using “define” you can expose things in your main javascript file to things inside other “require” functions.  I’m going to assume you are loading your main javascript file using a script tag in the same way you are loading dojo itself and that you are loading it from the URL /js/main.js  The first thing we want to do is to have dojo load your file itself, rather than you doing it through the script tag.  To do so, we have to consider it to be part of a “package”.  Before you load dojo, you should create a script tag that contains the following (not in a require):
var dojoConfig = {
packages: [ { name: ‘myApp’, location: ‘/js’ } ];
];

In your main require, add a dependency for "myApp/main”.  This will cause your main javascript file to be loaded and processed.  You will also need to add a corresponding argument to the require call back function.

In your main.js, change the “require” to “define”.  The parameters are the same: an array of dependencies and a callback function with an argument list that matches the array.  The only difference is that you will be returning something.  That something will be mapped to the parameter you added to your main require.  So it will look something like this:

define ([…], function (…) {
return {
validateUserEntered: function () {
//function body
},

// other functions you want to use outside this function
};
});

In your main require you would have

require ([…, ‘myApp/main’], function (…, main) {
parser.parse();
on(registry.byId(‘accountInfo’).domNode, ‘click’, function (evt) {
main.validateUserEntered().then(function (data) {
console.log(“valid user”);
});
});
});

On Mar 4, 2015, at 1:02 PM, Harry Devine <[hidden email]> wrote:

Sorry, still now working.  I'm defining my button as follows:

<button data-dojo-type="dijit/form/Button" type="button" id="accountInfo">Show Account Info</button>

In my main require, I have:

parser.parse();
on(dom.byId("accountInfo"), 'click', function(evt) {
  validateUserEntered().then(function(data) {
    return true;
  });
});

And in my main javascript file, I have validateUserEntered as follows:

function validateUserEntered() {
  var dfd = new Deferred();
  if (!registry.byId("username").get("value")) {
    dom.byId("ldapResult".innerHTML = "User name not specified!";
    dfd.reject("fail");
  }
  else {
    dfd.resolve("success");
  }
}

The error I get is:  Uncaught ReferenceError: validateUserEntered is not defined.

Obviously I'm missing something basic.  I'm trying to make my main javascript file have requires for all dojo modules I'll need in there, and then have the functions defined within the require/function blocks.  Like I mentioned earlier, I always had these types of errors doing it this way but having require/function in each sub function always worked, but according to Karl, this way is wrong.  So how do I fix this?

Thanks,
Harry




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

Harry Devine
I have an object, but no resolve on it.  It looks like its tied to the dijit/TextBox that I'm getting the value of:

domNode: div#widget_dijit_form_TextBox_0.dijit.dijitReset.dijitInline.dijitLeft.dijitTextBox

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:30:09 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

No problems.  I’m not judging…just trying to help.  I’m trying to give reasons for what’s wrong, not just telling you what to change so that, hopefully, it will be easier for you next time.  Did you make the change to have validateUserEntered return dfd?  If so, try putting a console.log(dfd) right above the dfd.resolve call and let me know what it logs for the object.  It should show an object that has a resolve function on it.

Steve

On Mar 9, 2015, at 12:16 PM, Harry Devine <[hidden email]> wrote:

Yes I am.  Sorry if I seem dense over this.  This whole Deferred thing is brand new to me.  Learning as I go.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:05:49 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

I didn’t notice this the first time, but your validateUserEntered function should return dfd, not true.  The return from validateUserEntered is the context for the “then” function.  I don’t think that explains the “undefined is not a function”, though.  Are you getting the “User name entered” output to the console right before the dd.resolve?


On Mar 9, 2015, at 11:50 AM, Harry Devine <[hidden email]> wrote:

OK, I fixed that (didn't understand what having that string there would do).  But I get the same error, only this time its on the line that says dfd.resolve. The error is Uncaught TypeError: undefined is not a function.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 9:16:58 AM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

The first thing I see is that you supplied the string parameter to define.  You are supposed to let the environment determine that with the location of the file.  Your file should be located at the url /ldap/accountinfo/utils.js.
The module is "ldapUtils/utils", not just utils as you have specified to define.

Steve
On Mar 9, 2015, at 7:47 AM, Harry Devine <[hidden email]> wrote:

OK, so I'm trudging through this slowly, and I can't get the function to work when I click the button.  I get Uncaught TypeError: undefined is not a function.  Here's my utils.js file now:

define("utils", [
  "dijit/registry",
  "dojo/Deferred"
], function(registry, Deferred) {
  return {
    validateUserEntered: function() {
      var dfd = new Deferred();
      if (!registry.byId("username").get("value")) {
        console.log("User name not entered!");
        dfd.reject("fail");
      }
      else {
        console.log("User name entered");
        dfd.resolve("success");
      }
      return true;
    }
  }
});

In my index.php:

<script>
  var dojoConfig = {
    tlmSiblingofDojo: false,
    packages: [
      {name: "ldapUtils", location: "/ldap/accountinfo"}
    ]
  };
</script>

require(...., "ldapUtils/utils")

then how I handle the button click:

on(dom.byId("accountInfo"), 'click', function(evt) {
  utils.validateUserEntered().then(function(data){                         <-------  this is where the error above is flagged
    console.log(data);
  });
});

Any ideas?
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Wednesday, March 4, 2015 2:55:41 PM
Subject: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator



Begin forwarded message:

From: Stephen Gevers <[hidden email]>
Subject: Re: [Dojo-interest] pwCheck function in PasswordValidator
Date: March 4, 2015 at 1:51:11 PM CST

I’m not sure what you mean by “main require” and “main javascript file”.  Is the main require in a script tag in HTML?  Is the function validateUserEntered embedded inside a require of it’s own?  That would explain your undefined function as validateUserEntered’s scope would be the require inside your main javascript file and not accessible to anything outside.  But even if you solve that, you still have issues in the code below.  In the “then” function you supply for validateUserEntered, where do you expect the “return true” to go?  Also, since your button is a widget, I don’t think you want dom.byId.  I believe you want on(registry.byId().domNode, …).  Or registry.byId().on(…).

The problem I think you are having is that you are trying to use AMD without creating any modules.  If I’m correct in the layout (and what you mean by main require and main javascript), you need to think of it this way: You have two different require invocations with two different callbacks.  The stuff that’s declared inside one of those call backs is not accessible to the other one without some trickery.  And that trickery is also considered bad practice.

So you need to restructure a bit.  Your main javascript file needs to have a “define” rather than a “require”.  By using “define” you can expose things in your main javascript file to things inside other “require” functions.  I’m going to assume you are loading your main javascript file using a script tag in the same way you are loading dojo itself and that you are loading it from the URL /js/main.js  The first thing we want to do is to have dojo load your file itself, rather than you doing it through the script tag.  To do so, we have to consider it to be part of a “package”.  Before you load dojo, you should create a script tag that contains the following (not in a require):
var dojoConfig = {
packages: [ { name: ‘myApp’, location: ‘/js’ } ];
];

In your main require, add a dependency for "myApp/main”.  This will cause your main javascript file to be loaded and processed.  You will also need to add a corresponding argument to the require call back function.

In your main.js, change the “require” to “define”.  The parameters are the same: an array of dependencies and a callback function with an argument list that matches the array.  The only difference is that you will be returning something.  That something will be mapped to the parameter you added to your main require.  So it will look something like this:

define ([…], function (…) {
return {
validateUserEntered: function () {
//function body
},

// other functions you want to use outside this function
};
});

In your main require you would have

require ([…, ‘myApp/main’], function (…, main) {
parser.parse();
on(registry.byId(‘accountInfo’).domNode, ‘click’, function (evt) {
main.validateUserEntered().then(function (data) {
console.log(“valid user”);
});
});
});

On Mar 4, 2015, at 1:02 PM, Harry Devine <[hidden email]> wrote:

Sorry, still now working.  I'm defining my button as follows:

<button data-dojo-type="dijit/form/Button" type="button" id="accountInfo">Show Account Info</button>

In my main require, I have:

parser.parse();
on(dom.byId("accountInfo"), 'click', function(evt) {
  validateUserEntered().then(function(data) {
    return true;
  });
});

And in my main javascript file, I have validateUserEntered as follows:

function validateUserEntered() {
  var dfd = new Deferred();
  if (!registry.byId("username").get("value")) {
    dom.byId("ldapResult".innerHTML = "User name not specified!";
    dfd.reject("fail");
  }
  else {
    dfd.resolve("success");
  }
}

The error I get is:  Uncaught ReferenceError: validateUserEntered is not defined.

Obviously I'm missing something basic.  I'm trying to make my main javascript file have requires for all dojo modules I'll need in there, and then have the functions defined within the require/function blocks.  Like I mentioned earlier, I always had these types of errors doing it this way but having require/function in each sub function always worked, but according to Karl, this way is wrong.  So how do I fix this?

Thanks,
Harry




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

Karl Tiedt
If you have not already, I would highly encourage you to move away from the dojoML pattern, it is great for fast mockup/testing but ultimately it will force you to write less than ideal code that is not nearly as maintainable or re-usable in the future.

-Karl Tiedt

On Mon, Mar 9, 2015 at 10:38 AM, Harry Devine <[hidden email]> wrote:
I have an object, but no resolve on it.  It looks like its tied to the dijit/TextBox that I'm getting the value of:

domNode: div#widget_dijit_form_TextBox_0.dijit.dijitReset.dijitInline.dijitLeft.dijitTextBox

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:30:09 PM

Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

No problems.  I’m not judging…just trying to help.  I’m trying to give reasons for what’s wrong, not just telling you what to change so that, hopefully, it will be easier for you next time.  Did you make the change to have validateUserEntered return dfd?  If so, try putting a console.log(dfd) right above the dfd.resolve call and let me know what it logs for the object.  It should show an object that has a resolve function on it.

Steve

On Mar 9, 2015, at 12:16 PM, Harry Devine <[hidden email]> wrote:

Yes I am.  Sorry if I seem dense over this.  This whole Deferred thing is brand new to me.  Learning as I go.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:05:49 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

I didn’t notice this the first time, but your validateUserEntered function should return dfd, not true.  The return from validateUserEntered is the context for the “then” function.  I don’t think that explains the “undefined is not a function”, though.  Are you getting the “User name entered” output to the console right before the dd.resolve?


On Mar 9, 2015, at 11:50 AM, Harry Devine <[hidden email]> wrote:

OK, I fixed that (didn't understand what having that string there would do).  But I get the same error, only this time its on the line that says dfd.resolve. The error is Uncaught TypeError: undefined is not a function.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 9:16:58 AM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

The first thing I see is that you supplied the string parameter to define.  You are supposed to let the environment determine that with the location of the file.  Your file should be located at the url /ldap/accountinfo/utils.js.
The module is "ldapUtils/utils", not just utils as you have specified to define.

Steve
On Mar 9, 2015, at 7:47 AM, Harry Devine <[hidden email]> wrote:

OK, so I'm trudging through this slowly, and I can't get the function to work when I click the button.  I get Uncaught TypeError: undefined is not a function.  Here's my utils.js file now:

define("utils", [
  "dijit/registry",
  "dojo/Deferred"
], function(registry, Deferred) {
  return {
    validateUserEntered: function() {
      var dfd = new Deferred();
      if (!registry.byId("username").get("value")) {
        console.log("User name not entered!");
        dfd.reject("fail");
      }
      else {
        console.log("User name entered");
        dfd.resolve("success");
      }
      return true;
    }
  }
});

In my index.php:

<script>
  var dojoConfig = {
    tlmSiblingofDojo: false,
    packages: [
      {name: "ldapUtils", location: "/ldap/accountinfo"}
    ]
  };
</script>

require(...., "ldapUtils/utils")

then how I handle the button click:

on(dom.byId("accountInfo"), 'click', function(evt) {
  utils.validateUserEntered().then(function(data){                         <-------  this is where the error above is flagged
    console.log(data);
  });
});

Any ideas?
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Wednesday, March 4, 2015 2:55:41 PM
Subject: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator



Begin forwarded message:

From: Stephen Gevers <[hidden email]>
Subject: Re: [Dojo-interest] pwCheck function in PasswordValidator
Date: March 4, 2015 at 1:51:11 PM CST

I’m not sure what you mean by “main require” and “main javascript file”.  Is the main require in a script tag in HTML?  Is the function validateUserEntered embedded inside a require of it’s own?  That would explain your undefined function as validateUserEntered’s scope would be the require inside your main javascript file and not accessible to anything outside.  But even if you solve that, you still have issues in the code below.  In the “then” function you supply for validateUserEntered, where do you expect the “return true” to go?  Also, since your button is a widget, I don’t think you want dom.byId.  I believe you want on(registry.byId().domNode, …).  Or registry.byId().on(…).

The problem I think you are having is that you are trying to use AMD without creating any modules.  If I’m correct in the layout (and what you mean by main require and main javascript), you need to think of it this way: You have two different require invocations with two different callbacks.  The stuff that’s declared inside one of those call backs is not accessible to the other one without some trickery.  And that trickery is also considered bad practice.

So you need to restructure a bit.  Your main javascript file needs to have a “define” rather than a “require”.  By using “define” you can expose things in your main javascript file to things inside other “require” functions.  I’m going to assume you are loading your main javascript file using a script tag in the same way you are loading dojo itself and that you are loading it from the URL /js/main.js  The first thing we want to do is to have dojo load your file itself, rather than you doing it through the script tag.  To do so, we have to consider it to be part of a “package”.  Before you load dojo, you should create a script tag that contains the following (not in a require):
var dojoConfig = {
packages: [ { name: ‘myApp’, location: ‘/js’ } ];
];

In your main require, add a dependency for "myApp/main”.  This will cause your main javascript file to be loaded and processed.  You will also need to add a corresponding argument to the require call back function.

In your main.js, change the “require” to “define”.  The parameters are the same: an array of dependencies and a callback function with an argument list that matches the array.  The only difference is that you will be returning something.  That something will be mapped to the parameter you added to your main require.  So it will look something like this:

define ([…], function (…) {
return {
validateUserEntered: function () {
//function body
},

// other functions you want to use outside this function
};
});

In your main require you would have

require ([…, ‘myApp/main’], function (…, main) {
parser.parse();
on(registry.byId(‘accountInfo’).domNode, ‘click’, function (evt) {
main.validateUserEntered().then(function (data) {
console.log(“valid user”);
});
});
});

On Mar 4, 2015, at 1:02 PM, Harry Devine <[hidden email]> wrote:

Sorry, still now working.  I'm defining my button as follows:

<button data-dojo-type="dijit/form/Button" type="button" id="accountInfo">Show Account Info</button>

In my main require, I have:

parser.parse();
on(dom.byId("accountInfo"), 'click', function(evt) {
  validateUserEntered().then(function(data) {
    return true;
  });
});

And in my main javascript file, I have validateUserEntered as follows:

function validateUserEntered() {
  var dfd = new Deferred();
  if (!registry.byId("username").get("value")) {
    dom.byId("ldapResult".innerHTML = "User name not specified!";
    dfd.reject("fail");
  }
  else {
    dfd.resolve("success");
  }
}

The error I get is:  Uncaught ReferenceError: validateUserEntered is not defined.

Obviously I'm missing something basic.  I'm trying to make my main javascript file have requires for all dojo modules I'll need in there, and then have the functions defined within the require/function blocks.  Like I mentioned earlier, I always had these types of errors doing it this way but having require/function in each sub function always worked, but according to Karl, this way is wrong.  So how do I fix this?

Thanks,
Harry




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

Harry Devine
What is the dojoML pattern?

Thanks,
Harry


From: "Karl Tiedt" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:52:25 PM
Subject: Re: [Dojo-interest] Fwd: pwCheck function in PasswordValidator

If you have not already, I would highly encourage you to move away from the dojoML pattern, it is great for fast mockup/testing but ultimately it will force you to write less than ideal code that is not nearly as maintainable or re-usable in the future.

-Karl Tiedt

On Mon, Mar 9, 2015 at 10:38 AM, Harry Devine <[hidden email]> wrote:
I have an object, but no resolve on it.  It looks like its tied to the dijit/TextBox that I'm getting the value of:

domNode: div#widget_dijit_form_TextBox_0.dijit.dijitReset.dijitInline.dijitLeft.dijitTextBox

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:30:09 PM

Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

No problems.  I’m not judging…just trying to help.  I’m trying to give reasons for what’s wrong, not just telling you what to change so that, hopefully, it will be easier for you next time.  Did you make the change to have validateUserEntered return dfd?  If so, try putting a console.log(dfd) right above the dfd.resolve call and let me know what it logs for the object.  It should show an object that has a resolve function on it.

Steve

On Mar 9, 2015, at 12:16 PM, Harry Devine <[hidden email]> wrote:

Yes I am.  Sorry if I seem dense over this.  This whole Deferred thing is brand new to me.  Learning as I go.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:05:49 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

I didn’t notice this the first time, but your validateUserEntered function should return dfd, not true.  The return from validateUserEntered is the context for the “then” function.  I don’t think that explains the “undefined is not a function”, though.  Are you getting the “User name entered” output to the console right before the dd.resolve?


On Mar 9, 2015, at 11:50 AM, Harry Devine <[hidden email]> wrote:

OK, I fixed that (didn't understand what having that string there would do).  But I get the same error, only this time its on the line that says dfd.resolve. The error is Uncaught TypeError: undefined is not a function.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 9:16:58 AM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

The first thing I see is that you supplied the string parameter to define.  You are supposed to let the environment determine that with the location of the file.  Your file should be located at the url /ldap/accountinfo/utils.js.
The module is "ldapUtils/utils", not just utils as you have specified to define.

Steve
On Mar 9, 2015, at 7:47 AM, Harry Devine <[hidden email]> wrote:

OK, so I'm trudging through this slowly, and I can't get the function to work when I click the button.  I get Uncaught TypeError: undefined is not a function.  Here's my utils.js file now:

define("utils", [
  "dijit/registry",
  "dojo/Deferred"
], function(registry, Deferred) {
  return {
    validateUserEntered: function() {
      var dfd = new Deferred();
      if (!registry.byId("username").get("value")) {
        console.log("User name not entered!");
        dfd.reject("fail");
      }
      else {
        console.log("User name entered");
        dfd.resolve("success");
      }
      return true;
    }
  }
});

In my index.php:

<script>
  var dojoConfig = {
    tlmSiblingofDojo: false,
    packages: [
      {name: "ldapUtils", location: "/ldap/accountinfo"}
    ]
  };
</script>

require(...., "ldapUtils/utils")

then how I handle the button click:

on(dom.byId("accountInfo"), 'click', function(evt) {
  utils.validateUserEntered().then(function(data){                         <-------  this is where the error above is flagged
    console.log(data);
  });
});

Any ideas?
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Wednesday, March 4, 2015 2:55:41 PM
Subject: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator



Begin forwarded message:

From: Stephen Gevers <[hidden email]>
Subject: Re: [Dojo-interest] pwCheck function in PasswordValidator
Date: March 4, 2015 at 1:51:11 PM CST

I’m not sure what you mean by “main require” and “main javascript file”.  Is the main require in a script tag in HTML?  Is the function validateUserEntered embedded inside a require of it’s own?  That would explain your undefined function as validateUserEntered’s scope would be the require inside your main javascript file and not accessible to anything outside.  But even if you solve that, you still have issues in the code below.  In the “then” function you supply for validateUserEntered, where do you expect the “return true” to go?  Also, since your button is a widget, I don’t think you want dom.byId.  I believe you want on(registry.byId().domNode, …).  Or registry.byId().on(…).

The problem I think you are having is that you are trying to use AMD without creating any modules.  If I’m correct in the layout (and what you mean by main require and main javascript), you need to think of it this way: You have two different require invocations with two different callbacks.  The stuff that’s declared inside one of those call backs is not accessible to the other one without some trickery.  And that trickery is also considered bad practice.

So you need to restructure a bit.  Your main javascript file needs to have a “define” rather than a “require”.  By using “define” you can expose things in your main javascript file to things inside other “require” functions.  I’m going to assume you are loading your main javascript file using a script tag in the same way you are loading dojo itself and that you are loading it from the URL /js/main.js  The first thing we want to do is to have dojo load your file itself, rather than you doing it through the script tag.  To do so, we have to consider it to be part of a “package”.  Before you load dojo, you should create a script tag that contains the following (not in a require):
var dojoConfig = {
packages: [ { name: ‘myApp’, location: ‘/js’ } ];
];

In your main require, add a dependency for "myApp/main”.  This will cause your main javascript file to be loaded and processed.  You will also need to add a corresponding argument to the require call back function.

In your main.js, change the “require” to “define”.  The parameters are the same: an array of dependencies and a callback function with an argument list that matches the array.  The only difference is that you will be returning something.  That something will be mapped to the parameter you added to your main require.  So it will look something like this:

define ([…], function (…) {
return {
validateUserEntered: function () {
//function body
},

// other functions you want to use outside this function
};
});

In your main require you would have

require ([…, ‘myApp/main’], function (…, main) {
parser.parse();
on(registry.byId(‘accountInfo’).domNode, ‘click’, function (evt) {
main.validateUserEntered().then(function (data) {
console.log(“valid user”);
});
});
});

On Mar 4, 2015, at 1:02 PM, Harry Devine <[hidden email]> wrote:

Sorry, still now working.  I'm defining my button as follows:

<button data-dojo-type="dijit/form/Button" type="button" id="accountInfo">Show Account Info</button>

In my main require, I have:

parser.parse();
on(dom.byId("accountInfo"), 'click', function(evt) {
  validateUserEntered().then(function(data) {
    return true;
  });
});

And in my main javascript file, I have validateUserEntered as follows:

function validateUserEntered() {
  var dfd = new Deferred();
  if (!registry.byId("username").get("value")) {
    dom.byId("ldapResult".innerHTML = "User name not specified!";
    dfd.reject("fail");
  }
  else {
    dfd.resolve("success");
  }
}

The error I get is:  Uncaught ReferenceError: validateUserEntered is not defined.

Obviously I'm missing something basic.  I'm trying to make my main javascript file have requires for all dojo modules I'll need in there, and then have the functions defined within the require/function blocks.  Like I mentioned earlier, I always had these types of errors doing it this way but having require/function in each sub function always worked, but according to Karl, this way is wrong.  So how do I fix this?

Thanks,
Harry




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

Karl Tiedt
<script type="dojo/method" data-dojo-event="pwCheck" data-dojo-args="password">
      checkPassword(password, successCallback, errorCallback);
      alert (bPwdValid);

      return bPwdValid;
    </script>

-Karl Tiedt

On Mon, Mar 9, 2015 at 10:59 AM, Harry Devine <[hidden email]> wrote:
What is the dojoML pattern?

Thanks,
Harry


From: "Karl Tiedt" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:52:25 PM

Subject: Re: [Dojo-interest] Fwd: pwCheck function in PasswordValidator

If you have not already, I would highly encourage you to move away from the dojoML pattern, it is great for fast mockup/testing but ultimately it will force you to write less than ideal code that is not nearly as maintainable or re-usable in the future.

-Karl Tiedt

On Mon, Mar 9, 2015 at 10:38 AM, Harry Devine <[hidden email]> wrote:
I have an object, but no resolve on it.  It looks like its tied to the dijit/TextBox that I'm getting the value of:

domNode: div#widget_dijit_form_TextBox_0.dijit.dijitReset.dijitInline.dijitLeft.dijitTextBox

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:30:09 PM

Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

No problems.  I’m not judging…just trying to help.  I’m trying to give reasons for what’s wrong, not just telling you what to change so that, hopefully, it will be easier for you next time.  Did you make the change to have validateUserEntered return dfd?  If so, try putting a console.log(dfd) right above the dfd.resolve call and let me know what it logs for the object.  It should show an object that has a resolve function on it.

Steve

On Mar 9, 2015, at 12:16 PM, Harry Devine <[hidden email]> wrote:

Yes I am.  Sorry if I seem dense over this.  This whole Deferred thing is brand new to me.  Learning as I go.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:05:49 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

I didn’t notice this the first time, but your validateUserEntered function should return dfd, not true.  The return from validateUserEntered is the context for the “then” function.  I don’t think that explains the “undefined is not a function”, though.  Are you getting the “User name entered” output to the console right before the dd.resolve?


On Mar 9, 2015, at 11:50 AM, Harry Devine <[hidden email]> wrote:

OK, I fixed that (didn't understand what having that string there would do).  But I get the same error, only this time its on the line that says dfd.resolve. The error is Uncaught TypeError: undefined is not a function.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 9:16:58 AM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

The first thing I see is that you supplied the string parameter to define.  You are supposed to let the environment determine that with the location of the file.  Your file should be located at the url /ldap/accountinfo/utils.js.
The module is "ldapUtils/utils", not just utils as you have specified to define.

Steve
On Mar 9, 2015, at 7:47 AM, Harry Devine <[hidden email]> wrote:

OK, so I'm trudging through this slowly, and I can't get the function to work when I click the button.  I get Uncaught TypeError: undefined is not a function.  Here's my utils.js file now:

define("utils", [
  "dijit/registry",
  "dojo/Deferred"
], function(registry, Deferred) {
  return {
    validateUserEntered: function() {
      var dfd = new Deferred();
      if (!registry.byId("username").get("value")) {
        console.log("User name not entered!");
        dfd.reject("fail");
      }
      else {
        console.log("User name entered");
        dfd.resolve("success");
      }
      return true;
    }
  }
});

In my index.php:

<script>
  var dojoConfig = {
    tlmSiblingofDojo: false,
    packages: [
      {name: "ldapUtils", location: "/ldap/accountinfo"}
    ]
  };
</script>

require(...., "ldapUtils/utils")

then how I handle the button click:

on(dom.byId("accountInfo"), 'click', function(evt) {
  utils.validateUserEntered().then(function(data){                         <-------  this is where the error above is flagged
    console.log(data);
  });
});

Any ideas?
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Wednesday, March 4, 2015 2:55:41 PM
Subject: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator



Begin forwarded message:

From: Stephen Gevers <[hidden email]>
Subject: Re: [Dojo-interest] pwCheck function in PasswordValidator
Date: March 4, 2015 at 1:51:11 PM CST

I’m not sure what you mean by “main require” and “main javascript file”.  Is the main require in a script tag in HTML?  Is the function validateUserEntered embedded inside a require of it’s own?  That would explain your undefined function as validateUserEntered’s scope would be the require inside your main javascript file and not accessible to anything outside.  But even if you solve that, you still have issues in the code below.  In the “then” function you supply for validateUserEntered, where do you expect the “return true” to go?  Also, since your button is a widget, I don’t think you want dom.byId.  I believe you want on(registry.byId().domNode, …).  Or registry.byId().on(…).

The problem I think you are having is that you are trying to use AMD without creating any modules.  If I’m correct in the layout (and what you mean by main require and main javascript), you need to think of it this way: You have two different require invocations with two different callbacks.  The stuff that’s declared inside one of those call backs is not accessible to the other one without some trickery.  And that trickery is also considered bad practice.

So you need to restructure a bit.  Your main javascript file needs to have a “define” rather than a “require”.  By using “define” you can expose things in your main javascript file to things inside other “require” functions.  I’m going to assume you are loading your main javascript file using a script tag in the same way you are loading dojo itself and that you are loading it from the URL /js/main.js  The first thing we want to do is to have dojo load your file itself, rather than you doing it through the script tag.  To do so, we have to consider it to be part of a “package”.  Before you load dojo, you should create a script tag that contains the following (not in a require):
var dojoConfig = {
packages: [ { name: ‘myApp’, location: ‘/js’ } ];
];

In your main require, add a dependency for "myApp/main”.  This will cause your main javascript file to be loaded and processed.  You will also need to add a corresponding argument to the require call back function.

In your main.js, change the “require” to “define”.  The parameters are the same: an array of dependencies and a callback function with an argument list that matches the array.  The only difference is that you will be returning something.  That something will be mapped to the parameter you added to your main require.  So it will look something like this:

define ([…], function (…) {
return {
validateUserEntered: function () {
//function body
},

// other functions you want to use outside this function
};
});

In your main require you would have

require ([…, ‘myApp/main’], function (…, main) {
parser.parse();
on(registry.byId(‘accountInfo’).domNode, ‘click’, function (evt) {
main.validateUserEntered().then(function (data) {
console.log(“valid user”);
});
});
});

On Mar 4, 2015, at 1:02 PM, Harry Devine <[hidden email]> wrote:

Sorry, still now working.  I'm defining my button as follows:

<button data-dojo-type="dijit/form/Button" type="button" id="accountInfo">Show Account Info</button>

In my main require, I have:

parser.parse();
on(dom.byId("accountInfo"), 'click', function(evt) {
  validateUserEntered().then(function(data) {
    return true;
  });
});

And in my main javascript file, I have validateUserEntered as follows:

function validateUserEntered() {
  var dfd = new Deferred();
  if (!registry.byId("username").get("value")) {
    dom.byId("ldapResult".innerHTML = "User name not specified!";
    dfd.reject("fail");
  }
  else {
    dfd.resolve("success");
  }
}

The error I get is:  Uncaught ReferenceError: validateUserEntered is not defined.

Obviously I'm missing something basic.  I'm trying to make my main javascript file have requires for all dojo modules I'll need in there, and then have the functions defined within the require/function blocks.  Like I mentioned earlier, I always had these types of errors doing it this way but having require/function in each sub function always worked, but according to Karl, this way is wrong.  So how do I fix this?

Thanks,
Harry




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

sg3235
In reply to this post by Harry Devine
I really don’t see how your dfd could be a reference to a dom node based on your code snippet.  Any chance you could create a jsfiddle?

On Mar 9, 2015, at 12:38 PM, Harry Devine <[hidden email]> wrote:

I have an object, but no resolve on it.  It looks like its tied to the dijit/TextBox that I'm getting the value of:

domNode: div#widget_dijit_form_TextBox_0.dijit.dijitReset.dijitInline.dijitLeft.dijitTextBox

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:30:09 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

No problems.  I’m not judging…just trying to help.  I’m trying to give reasons for what’s wrong, not just telling you what to change so that, hopefully, it will be easier for you next time.  Did you make the change to have validateUserEntered return dfd?  If so, try putting a console.log(dfd) right above the dfd.resolve call and let me know what it logs for the object.  It should show an object that has a resolve function on it.

Steve

On Mar 9, 2015, at 12:16 PM, Harry Devine <[hidden email]> wrote:

Yes I am.  Sorry if I seem dense over this.  This whole Deferred thing is brand new to me.  Learning as I go.

Thanks,
Harry



From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:05:49 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

I didn’t notice this the first time, but your validateUserEntered function should return dfd, not true.  The return from validateUserEntered is the context for the “then” function.  I don’t think that explains the “undefined is not a function”, though.  Are you getting the “User name entered” output to the console right before the dd.resolve?


On Mar 9, 2015, at 11:50 AM, Harry Devine <[hidden email]> wrote:

OK, I fixed that (didn't understand what having that string there would do).  But I get the same error, only this time its on the line that says dfd.resolve. The error is Uncaught TypeError: undefined is not a function.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 9:16:58 AM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

The first thing I see is that you supplied the string parameter to define.  You are supposed to let the environment determine that with the location of the file.  Your file should be located at the url /ldap/accountinfo/utils.js.
The module is "ldapUtils/utils", not just utils as you have specified to define.

Steve
On Mar 9, 2015, at 7:47 AM, Harry Devine <[hidden email]> wrote:

OK, so I'm trudging through this slowly, and I can't get the function to work when I click the button.  I get Uncaught TypeError: undefined is not a function.  Here's my utils.js file now:

define("utils", [
  "dijit/registry",
  "dojo/Deferred"
], function(registry, Deferred) {
  return {
    validateUserEntered: function() {
      var dfd = new Deferred();
      if (!registry.byId("username").get("value")) {
        console.log("User name not entered!");
        dfd.reject("fail");
      }
      else {
        console.log("User name entered");
        dfd.resolve("success");
      }
      return true;
    }
  }
});

In my index.php:

<script>
  var dojoConfig = {
    tlmSiblingofDojo: false,
    packages: [
      {name: "ldapUtils", location: "/ldap/accountinfo"}
    ]
  };
</script>

require(...., "ldapUtils/utils")

then how I handle the button click:

on(dom.byId("accountInfo"), 'click', function(evt) {
  utils.validateUserEntered().then(function(data){                         <-------  this is where the error above is flagged
    console.log(data);
  });
});

Any ideas?
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Wednesday, March 4, 2015 2:55:41 PM
Subject: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator



Begin forwarded message:

From: Stephen Gevers <[hidden email]>
Subject: Re: [Dojo-interest] pwCheck function in PasswordValidator
Date: March 4, 2015 at 1:51:11 PM CST

I’m not sure what you mean by “main require” and “main javascript file”.  Is the main require in a script tag in HTML?  Is the function validateUserEntered embedded inside a require of it’s own?  That would explain your undefined function as validateUserEntered’s scope would be the require inside your main javascript file and not accessible to anything outside.  But even if you solve that, you still have issues in the code below.  In the “then” function you supply for validateUserEntered, where do you expect the “return true” to go?  Also, since your button is a widget, I don’t think you want dom.byId.  I believe you want on(registry.byId().domNode, …).  Or registry.byId().on(…).

The problem I think you are having is that you are trying to use AMD without creating any modules.  If I’m correct in the layout (and what you mean by main require and main javascript), you need to think of it this way: You have two different require invocations with two different callbacks.  The stuff that’s declared inside one of those call backs is not accessible to the other one without some trickery.  And that trickery is also considered bad practice.

So you need to restructure a bit.  Your main javascript file needs to have a “define” rather than a “require”.  By using “define” you can expose things in your main javascript file to things inside other “require” functions.  I’m going to assume you are loading your main javascript file using a script tag in the same way you are loading dojo itself and that you are loading it from the URL /js/main.js  The first thing we want to do is to have dojo load your file itself, rather than you doing it through the script tag.  To do so, we have to consider it to be part of a “package”.  Before you load dojo, you should create a script tag that contains the following (not in a require):
var dojoConfig = {
packages: [ { name: ‘myApp’, location: ‘/js’ } ];
];

In your main require, add a dependency for "myApp/main”.  This will cause your main javascript file to be loaded and processed.  You will also need to add a corresponding argument to the require call back function.

In your main.js, change the “require” to “define”.  The parameters are the same: an array of dependencies and a callback function with an argument list that matches the array.  The only difference is that you will be returning something.  That something will be mapped to the parameter you added to your main require.  So it will look something like this:

define ([…], function (…) {
return {
validateUserEntered: function () {
//function body
},

// other functions you want to use outside this function
};
});

In your main require you would have

require ([…, ‘myApp/main’], function (…, main) {
parser.parse();
on(registry.byId(‘accountInfo’).domNode, ‘click’, function (evt) {
main.validateUserEntered().then(function (data) {
console.log(“valid user”);
});
});
});

On Mar 4, 2015, at 1:02 PM, Harry Devine <[hidden email]> wrote:

Sorry, still now working.  I'm defining my button as follows:

<button data-dojo-type="dijit/form/Button" type="button" id="accountInfo">Show Account Info</button>

In my main require, I have:

parser.parse();
on(dom.byId("accountInfo"), 'click', function(evt) {
  validateUserEntered().then(function(data) {
    return true;
  });
});

And in my main javascript file, I have validateUserEntered as follows:

function validateUserEntered() {
  var dfd = new Deferred();
  if (!registry.byId("username").get("value")) {
    dom.byId("ldapResult".innerHTML = "User name not specified!";
    dfd.reject("fail");
  }
  else {
    dfd.resolve("success");
  }
}

The error I get is:  Uncaught ReferenceError: validateUserEntered is not defined.

Obviously I'm missing something basic.  I'm trying to make my main javascript file have requires for all dojo modules I'll need in there, and then have the functions defined within the require/function blocks.  Like I mentioned earlier, I always had these types of errors doing it this way but having require/function in each sub function always worked, but according to Karl, this way is wrong.  So how do I fix this?

Thanks,
Harry




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

Harry Devine
In reply to this post by Karl Tiedt
Should I do some sort of dojo/on then?  Something like:

on(dom.byId("pwdVerify"), 'pwCheck', function(evt){
  checkPassword();
});

Thanks,
Harry


From: "Karl Tiedt" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 2:01:35 PM
Subject: Re: [Dojo-interest] Fwd: pwCheck function in PasswordValidator

<script type="dojo/method" data-dojo-event="pwCheck" data-dojo-args="password">
      checkPassword(password, successCallback, errorCallback);
      alert (bPwdValid);

      return bPwdValid;
    </script>

-Karl Tiedt

On Mon, Mar 9, 2015 at 10:59 AM, Harry Devine <[hidden email]> wrote:
What is the dojoML pattern?

Thanks,
Harry


From: "Karl Tiedt" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:52:25 PM

Subject: Re: [Dojo-interest] Fwd: pwCheck function in PasswordValidator

If you have not already, I would highly encourage you to move away from the dojoML pattern, it is great for fast mockup/testing but ultimately it will force you to write less than ideal code that is not nearly as maintainable or re-usable in the future.

-Karl Tiedt

On Mon, Mar 9, 2015 at 10:38 AM, Harry Devine <[hidden email]> wrote:
I have an object, but no resolve on it.  It looks like its tied to the dijit/TextBox that I'm getting the value of:

domNode: div#widget_dijit_form_TextBox_0.dijit.dijitReset.dijitInline.dijitLeft.dijitTextBox

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:30:09 PM

Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

No problems.  I’m not judging…just trying to help.  I’m trying to give reasons for what’s wrong, not just telling you what to change so that, hopefully, it will be easier for you next time.  Did you make the change to have validateUserEntered return dfd?  If so, try putting a console.log(dfd) right above the dfd.resolve call and let me know what it logs for the object.  It should show an object that has a resolve function on it.

Steve

On Mar 9, 2015, at 12:16 PM, Harry Devine <[hidden email]> wrote:

Yes I am.  Sorry if I seem dense over this.  This whole Deferred thing is brand new to me.  Learning as I go.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:05:49 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

I didn’t notice this the first time, but your validateUserEntered function should return dfd, not true.  The return from validateUserEntered is the context for the “then” function.  I don’t think that explains the “undefined is not a function”, though.  Are you getting the “User name entered” output to the console right before the dd.resolve?


On Mar 9, 2015, at 11:50 AM, Harry Devine <[hidden email]> wrote:

OK, I fixed that (didn't understand what having that string there would do).  But I get the same error, only this time its on the line that says dfd.resolve. The error is Uncaught TypeError: undefined is not a function.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 9:16:58 AM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

The first thing I see is that you supplied the string parameter to define.  You are supposed to let the environment determine that with the location of the file.  Your file should be located at the url /ldap/accountinfo/utils.js.
The module is "ldapUtils/utils", not just utils as you have specified to define.

Steve
On Mar 9, 2015, at 7:47 AM, Harry Devine <[hidden email]> wrote:

OK, so I'm trudging through this slowly, and I can't get the function to work when I click the button.  I get Uncaught TypeError: undefined is not a function.  Here's my utils.js file now:

define("utils", [
  "dijit/registry",
  "dojo/Deferred"
], function(registry, Deferred) {
  return {
    validateUserEntered: function() {
      var dfd = new Deferred();
      if (!registry.byId("username").get("value")) {
        console.log("User name not entered!");
        dfd.reject("fail");
      }
      else {
        console.log("User name entered");
        dfd.resolve("success");
      }
      return true;
    }
  }
});

In my index.php:

<script>
  var dojoConfig = {
    tlmSiblingofDojo: false,
    packages: [
      {name: "ldapUtils", location: "/ldap/accountinfo"}
    ]
  };
</script>

require(...., "ldapUtils/utils")

then how I handle the button click:

on(dom.byId("accountInfo"), 'click', function(evt) {
  utils.validateUserEntered().then(function(data){                         <-------  this is where the error above is flagged
    console.log(data);
  });
});

Any ideas?
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Wednesday, March 4, 2015 2:55:41 PM
Subject: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator



Begin forwarded message:

From: Stephen Gevers <[hidden email]>
Subject: Re: [Dojo-interest] pwCheck function in PasswordValidator
Date: March 4, 2015 at 1:51:11 PM CST

I’m not sure what you mean by “main require” and “main javascript file”.  Is the main require in a script tag in HTML?  Is the function validateUserEntered embedded inside a require of it’s own?  That would explain your undefined function as validateUserEntered’s scope would be the require inside your main javascript file and not accessible to anything outside.  But even if you solve that, you still have issues in the code below.  In the “then” function you supply for validateUserEntered, where do you expect the “return true” to go?  Also, since your button is a widget, I don’t think you want dom.byId.  I believe you want on(registry.byId().domNode, …).  Or registry.byId().on(…).

The problem I think you are having is that you are trying to use AMD without creating any modules.  If I’m correct in the layout (and what you mean by main require and main javascript), you need to think of it this way: You have two different require invocations with two different callbacks.  The stuff that’s declared inside one of those call backs is not accessible to the other one without some trickery.  And that trickery is also considered bad practice.

So you need to restructure a bit.  Your main javascript file needs to have a “define” rather than a “require”.  By using “define” you can expose things in your main javascript file to things inside other “require” functions.  I’m going to assume you are loading your main javascript file using a script tag in the same way you are loading dojo itself and that you are loading it from the URL /js/main.js  The first thing we want to do is to have dojo load your file itself, rather than you doing it through the script tag.  To do so, we have to consider it to be part of a “package”.  Before you load dojo, you should create a script tag that contains the following (not in a require):
var dojoConfig = {
packages: [ { name: ‘myApp’, location: ‘/js’ } ];
];

In your main require, add a dependency for "myApp/main”.  This will cause your main javascript file to be loaded and processed.  You will also need to add a corresponding argument to the require call back function.

In your main.js, change the “require” to “define”.  The parameters are the same: an array of dependencies and a callback function with an argument list that matches the array.  The only difference is that you will be returning something.  That something will be mapped to the parameter you added to your main require.  So it will look something like this:

define ([…], function (…) {
return {
validateUserEntered: function () {
//function body
},

// other functions you want to use outside this function
};
});

In your main require you would have

require ([…, ‘myApp/main’], function (…, main) {
parser.parse();
on(registry.byId(‘accountInfo’).domNode, ‘click’, function (evt) {
main.validateUserEntered().then(function (data) {
console.log(“valid user”);
});
});
});

On Mar 4, 2015, at 1:02 PM, Harry Devine <[hidden email]> wrote:

Sorry, still now working.  I'm defining my button as follows:

<button data-dojo-type="dijit/form/Button" type="button" id="accountInfo">Show Account Info</button>

In my main require, I have:

parser.parse();
on(dom.byId("accountInfo"), 'click', function(evt) {
  validateUserEntered().then(function(data) {
    return true;
  });
});

And in my main javascript file, I have validateUserEntered as follows:

function validateUserEntered() {
  var dfd = new Deferred();
  if (!registry.byId("username").get("value")) {
    dom.byId("ldapResult".innerHTML = "User name not specified!";
    dfd.reject("fail");
  }
  else {
    dfd.resolve("success");
  }
}

The error I get is:  Uncaught ReferenceError: validateUserEntered is not defined.

Obviously I'm missing something basic.  I'm trying to make my main javascript file have requires for all dojo modules I'll need in there, and then have the functions defined within the require/function blocks.  Like I mentioned earlier, I always had these types of errors doing it this way but having require/function in each sub function always worked, but according to Karl, this way is wrong.  So how do I fix this?

Thanks,
Harry




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

Harry Devine
In reply to this post by sg3235
Trying that now.  How do I handle this new module in JSFiddle?  Just paste the entire js file into the javascript section?

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 2:09:22 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

I really don’t see how your dfd could be a reference to a dom node based on your code snippet.  Any chance you could create a jsfiddle?

On Mar 9, 2015, at 12:38 PM, Harry Devine <[hidden email]> wrote:

I have an object, but no resolve on it.  It looks like its tied to the dijit/TextBox that I'm getting the value of:

domNode: div#widget_dijit_form_TextBox_0.dijit.dijitReset.dijitInline.dijitLeft.dijitTextBox

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:30:09 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

No problems.  I’m not judging…just trying to help.  I’m trying to give reasons for what’s wrong, not just telling you what to change so that, hopefully, it will be easier for you next time.  Did you make the change to have validateUserEntered return dfd?  If so, try putting a console.log(dfd) right above the dfd.resolve call and let me know what it logs for the object.  It should show an object that has a resolve function on it.

Steve

On Mar 9, 2015, at 12:16 PM, Harry Devine <[hidden email]> wrote:

Yes I am.  Sorry if I seem dense over this.  This whole Deferred thing is brand new to me.  Learning as I go.

Thanks,
Harry



From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 1:05:49 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

I didn’t notice this the first time, but your validateUserEntered function should return dfd, not true.  The return from validateUserEntered is the context for the “then” function.  I don’t think that explains the “undefined is not a function”, though.  Are you getting the “User name entered” output to the console right before the dd.resolve?


On Mar 9, 2015, at 11:50 AM, Harry Devine <[hidden email]> wrote:

OK, I fixed that (didn't understand what having that string there would do).  But I get the same error, only this time its on the line that says dfd.resolve. The error is Uncaught TypeError: undefined is not a function.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 9:16:58 AM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

The first thing I see is that you supplied the string parameter to define.  You are supposed to let the environment determine that with the location of the file.  Your file should be located at the url /ldap/accountinfo/utils.js.
The module is "ldapUtils/utils", not just utils as you have specified to define.

Steve
On Mar 9, 2015, at 7:47 AM, Harry Devine <[hidden email]> wrote:

OK, so I'm trudging through this slowly, and I can't get the function to work when I click the button.  I get Uncaught TypeError: undefined is not a function.  Here's my utils.js file now:

define("utils", [
  "dijit/registry",
  "dojo/Deferred"
], function(registry, Deferred) {
  return {
    validateUserEntered: function() {
      var dfd = new Deferred();
      if (!registry.byId("username").get("value")) {
        console.log("User name not entered!");
        dfd.reject("fail");
      }
      else {
        console.log("User name entered");
        dfd.resolve("success");
      }
      return true;
    }
  }
});

In my index.php:

<script>
  var dojoConfig = {
    tlmSiblingofDojo: false,
    packages: [
      {name: "ldapUtils", location: "/ldap/accountinfo"}
    ]
  };
</script>

require(...., "ldapUtils/utils")

then how I handle the button click:

on(dom.byId("accountInfo"), 'click', function(evt) {
  utils.validateUserEntered().then(function(data){                         <-------  this is where the error above is flagged
    console.log(data);
  });
});

Any ideas?
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Wednesday, March 4, 2015 2:55:41 PM
Subject: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator



Begin forwarded message:

From: Stephen Gevers <[hidden email]>
Subject: Re: [Dojo-interest] pwCheck function in PasswordValidator
Date: March 4, 2015 at 1:51:11 PM CST

I’m not sure what you mean by “main require” and “main javascript file”.  Is the main require in a script tag in HTML?  Is the function validateUserEntered embedded inside a require of it’s own?  That would explain your undefined function as validateUserEntered’s scope would be the require inside your main javascript file and not accessible to anything outside.  But even if you solve that, you still have issues in the code below.  In the “then” function you supply for validateUserEntered, where do you expect the “return true” to go?  Also, since your button is a widget, I don’t think you want dom.byId.  I believe you want on(registry.byId().domNode, …).  Or registry.byId().on(…).

The problem I think you are having is that you are trying to use AMD without creating any modules.  If I’m correct in the layout (and what you mean by main require and main javascript), you need to think of it this way: You have two different require invocations with two different callbacks.  The stuff that’s declared inside one of those call backs is not accessible to the other one without some trickery.  And that trickery is also considered bad practice.

So you need to restructure a bit.  Your main javascript file needs to have a “define” rather than a “require”.  By using “define” you can expose things in your main javascript file to things inside other “require” functions.  I’m going to assume you are loading your main javascript file using a script tag in the same way you are loading dojo itself and that you are loading it from the URL /js/main.js  The first thing we want to do is to have dojo load your file itself, rather than you doing it through the script tag.  To do so, we have to consider it to be part of a “package”.  Before you load dojo, you should create a script tag that contains the following (not in a require):
var dojoConfig = {
packages: [ { name: ‘myApp’, location: ‘/js’ } ];
];

In your main require, add a dependency for "myApp/main”.  This will cause your main javascript file to be loaded and processed.  You will also need to add a corresponding argument to the require call back function.

In your main.js, change the “require” to “define”.  The parameters are the same: an array of dependencies and a callback function with an argument list that matches the array.  The only difference is that you will be returning something.  That something will be mapped to the parameter you added to your main require.  So it will look something like this:

define ([…], function (…) {
return {
validateUserEntered: function () {
//function body
},

// other functions you want to use outside this function
};
});

In your main require you would have

require ([…, ‘myApp/main’], function (…, main) {
parser.parse();
on(registry.byId(‘accountInfo’).domNode, ‘click’, function (evt) {
main.validateUserEntered().then(function (data) {
console.log(“valid user”);
});
});
});

On Mar 4, 2015, at 1:02 PM, Harry Devine <[hidden email]> wrote:

Sorry, still now working.  I'm defining my button as follows:

<button data-dojo-type="dijit/form/Button" type="button" id="accountInfo">Show Account Info</button>

In my main require, I have:

parser.parse();
on(dom.byId("accountInfo"), 'click', function(evt) {
  validateUserEntered().then(function(data) {
    return true;
  });
});

And in my main javascript file, I have validateUserEntered as follows:

function validateUserEntered() {
  var dfd = new Deferred();
  if (!registry.byId("username").get("value")) {
    dom.byId("ldapResult".innerHTML = "User name not specified!";
    dfd.reject("fail");
  }
  else {
    dfd.resolve("success");
  }
}

The error I get is:  Uncaught ReferenceError: validateUserEntered is not defined.

Obviously I'm missing something basic.  I'm trying to make my main javascript file have requires for all dojo modules I'll need in there, and then have the functions defined within the require/function blocks.  Like I mentioned earlier, I always had these types of errors doing it this way but having require/function in each sub function always worked, but according to Karl, this way is wrong.  So how do I fix this?

Thanks,
Harry




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

Harry Devine
In reply to this post by sg3235
Here's my JSFiddle attempt:  http://jsfiddle.net/8d6hkdf3/.  I had to put the button's click handler with the button using dojo/method because I couldn't figure out how to use the on handler that I have in the real code.  Hopefully someone can enlighten me.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 2:09:22 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

I really don’t see how your dfd could be a reference to a dom node based on your code snippet.  Any chance you could create a jsfiddle?



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: pwCheck function in PasswordValidator

sg3235
So I looked at your fiddle.  There is no username field in the HTML, so registry.byId(‘username’) should return null.  The next thing I noticed is that if you fail, you return false.  Remember, you can’t run .then() on the return from validateUserEntered if you don’t return a promise (Deferred).  Finally, your <script type=“dojo/on”> is referencing a global function that doesn’t exist.  You need to get away from that and assign that handler inside of a require so that you can have access to the function in the define.

On Mar 10, 2015, at 2:16 PM, Harry Devine <[hidden email]> wrote:



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

Karl Tiedt
In reply to this post by Harry Devine
Quite a few updates to make your Fiddle work but this is working w/o the dojo Markup


-Karl Tiedt

On Tue, Mar 10, 2015 at 12:16 PM, Harry Devine <[hidden email]> wrote:
Here's my JSFiddle attempt:  http://jsfiddle.net/8d6hkdf3/.  I had to put the button's click handler with the button using dojo/method because I couldn't figure out how to use the on handler that I have in the real code.  Hopefully someone can enlighten me.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 2:09:22 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

I really don’t see how your dfd could be a reference to a dom node based on your code snippet.  Any chance you could create a jsfiddle?



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: pwCheck function in PasswordValidator

Harry Devine
Thanks Karl!  I'm going away for a few days so I won't get back to this until next week.  But I was trying to get a fiddle that has my custom module in it.  How do I do that?

Thanks,
Harry

Sent from Outlook




On Tue, Mar 10, 2015 at 1:26 PM -0700, "Karl Tiedt" <[hidden email]> wrote:

Quite a few updates to make your Fiddle work but this is working w/o the dojo Markup


-Karl Tiedt

On Tue, Mar 10, 2015 at 12:16 PM, Harry Devine <[hidden email]> wrote:
Here's my JSFiddle attempt:  http://jsfiddle.net/8d6hkdf3/.  I had to put the button's click handler with the button using dojo/method because I couldn't figure out how to use the on handler that I have in the real code.  Hopefully someone can enlighten me.

Thanks,
Harry


From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Monday, March 9, 2015 2:09:22 PM
Subject: Re: [Dojo-interest] Fwd:  pwCheck function in PasswordValidator

I really don’t see how your dfd could be a reference to a dom node based on your code snippet.  Any chance you could create a jsfiddle?



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: pwCheck function in PasswordValidator

Harry Devine
In reply to this post by sg3235
I'll be away for a few days but I'll get back to it next week.  You suggested I make my JavaScript file it's own module by changing require to define and modifying how the functions are declared.  How do I put this into the JSFiddle?  Thats what I wanted to do but couldn't make work, and the fiddle you saw was what I started with.  Or should I just send you my code off-list?

Thanks,
Harry


Sent by Outlook for Android



On Tue, Mar 10, 2015 at 12:56 PM -0700, "Stephen Gevers" <[hidden email]> wrote:

So I looked at your fiddle.  There is no username field in the HTML, so registry.byId(‘username’) should return null.  The next thing I noticed is that if you fail, you return false.  Remember, you can’t run .then() on the return from validateUserEntered if you don’t return a promise (Deferred).  Finally, your <script type=“dojo/on”> is referencing a global function that doesn’t exist.  You need to get away from that and assign that handler inside of a require so that you can have access to the function in the define.

On Mar 10, 2015, at 2:16 PM, Harry Devine <[hidden email]> wrote:



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: pwCheck function in PasswordValidator

Harry Devine
In reply to this post by sg3235
OK, I'm getting back to this.  I'm going to put the code I'm using in hopes of 2 things:

1) someone can tell me how to make the define I have in utils.js work in JSFiddle;
2) maybe someone can see why, in my validateUserEntered function in utils.js, the dfd object defaults to dijit/form/TextBox, thereby throwing the error "dfd.resolve is not a function" in Firebug.

Thanks,
Harry

index.php:

<html>
<head>
<meta charset="utf-8">
<title>Account Information Utility</title>

<style type="text/css">
@import "/dojoroot/dojo/resources/dojo.css";
@import "/dojoroot/dijit/themes/dijit.css";
@import "/dojoroot/dijit/themes/claro/claro.css";
@import "/css/carts.css";
</style>

<script>
var dojoConfig = {
tlmSiblingOfDojo: false,
packages: [
{name: "ldapUtils", location: "/ldap/accountinfo"}
]
};
</script>
<script type="text/javascript" src="/dojoroot/dojo/dojo.js" data-dojo-config="async:1,parseOnLoad:true"></script>
<!--<script src="/ldap/accountinfo/utils.js"></script> -->
<script type="text/javascript">
require(["dojo/parser",
"dijit/form/Button",
"dijit/form/TextBox",
"dojo/on",
"dijit/registry",
"dojo/request",
"dojox/form/PasswordValidator",
"dojo/ready",
"dojo/Deferred",
"dojo/dom",
"ldapUtils/utils",
"dojo/domReady!"],
function(parser,Button,TextBox,on,registry,request,PasswordValidator,ready,Deferred, dom, utils) {
ready(function() {
parser.parse();

/* Handler for the Show Account Info button click */
on(dom.byId("accountInfo"), 'click', function(evt){
utils.validateUserEntered().then(function(data){
console.log(data);
});
});
});
});
</script>
</head>

<body class="claro">
<center>
<img src="/images/TAMR_CARTS_Logo.JPG"><h1>Terminal Server - Account Information Utility</h1><br>
Enter your Terminal Server user name and select "Show Account Info".
</center>
<br><br><br>
<center>
<label for="username">User Name:</label>
<input type="text" name="username" data-dojo-type="dijit/form/TextBox" data-dojo-id="username" id="username"/><br><br>
<button data-dojo-type="dijit/form/Button" type="button" id="accountInfo">Show Account Info</button>
<div id="ldapResult"></div>
<div id="ldapIP"></div>
<div class="cartsAddAccountTable">
<div class="cartsAddAccountTableRow">
<div class="cartsAddAccountTableColumn">
<div id="userRow" class="cartsContent"></div>
</div>
<div class="cartsAddAccountTableColumn">
<div id="ldapUser" class="cartsContent"></div>
</div>
</div>
<div class="cartsAddAccountTableRow">
<div class="cartsAddAccountTableColumn">
<div id="emailRow" class="cartsContent"></div>
</div>
<div class="cartsAddAccountTableColumn">
<div id="ldapEmail" class="cartsContent"></div>
</div>
</div>
<div class="cartsAddAccountTableRow">
<div class="cartsAddAccountTableColumn">
<div id="phoneRow" class="cartsContent"></div>
</div>
<div class="cartsAddAccountTableColumn">
<div id="ldapPhone" class="cartsContent"></div>
</div>
</div>
<div class="cartsAddAccountTableRow">
<div class="cartsAddAccountTableColumn">
<div id="ageRow" class="cartsContent"></div>
</div>
<div class="cartsAddAccountTableColumn">
<div id="ldapAge" class="cartsContent"></div>
</div>
</div>
<div class="cartsAddAccountTableRow">
<div class="cartsAddAccountTableColumn">
<div id="loginRow" class="cartsContent"></div>
</div>
<div class="cartsAddAccountTableColumn">
<div id="ldapLogin" class="cartsContent"></div>
</div>
</div>
<div class="cartsAddAccountTableRow">
<div class="cartsAddAccountTableColumn">
<div id="lockRow" class="cartsContent"></div>
</div>
<div class="cartsAddAccountTableColumn">
<div id="ldapLocked" class="cartsContent"></div>
</div>
</div>
<div class="cartsAddAccountTableRow">
<div class="cartsAddAccountTableColumn">
<div id="unlockTimeRow" class="cartsContent"></div>
</div>
<div class="cartsAddAccountTableColumn">
<div id="ldapAccountLockout" class="cartsContent"></div>
</div>
</div>
<div class="cartsAddAccountTableRow">
</div>
<div class="cartsAddAccountTableRow">
</div>
<div class="cartsAddAccountTableRow">
<div class="cartsAddAccountTableColumn">
<div id="ldapTempPwd" class="cartsContent"></div>
</div>
<div class="cartsAddAccountTableColumn">
<div id="ldapChgPwd" class="cartsContent"></div>
</div>
</div>
</div>
<div id="ldapPasswordArea" class="cartsChgPwdArea">
<div id="ldapPasswordAreaHelp" class="cartsHelp">Enter your old password and choose a new one</div>
<div class="cartsAddAccountTable">
<div class="cartsAddAccountTableRow"></div>
<div class="cartsAddAccountTableRow"></div>
<div class="cartsAddAccountTableRow"></div>
<div data-dojo-type="dojox/form/PasswordValidator" name="pwdVerify">
<div class="cartsAddAccountTableRow">
<div class="cartsAddAccountTableColumn"><b>Old (or Temp) Password:</b></div>
<div class="cartsAddAccountTableColumn">
<div class="cartsAddAccountTableColumn"><input type="password" pwType="old"></div><br>
</div>
</div>
<div class="cartsAddAccountTableRow">
<div class="cartsAddAccountTableColumn"><b>New Password:</b></div>
<div class="cartsAddAccountTableColumn">
<div class="cartsAddAccountTableColumn"><input type="password" pwType="new"></div><br>
</div>
</div>
<div class="cartsAddAccountTableRow">
<div class="cartsAddAccountTableColumn"><b>Confirm Password:</b></div>
<div class="cartsAddAccountTableColumn">
<div class="cartsAddAccountTableColumn"><input type="password" pwType="verify"></div><br>
</div>
</div>
</div>
<div class="cartsAddAccountTableRow">
<div class="cartsAddAccountTableColumn">
<div id="ldapPwdAreaSendPwd" class="cartsChgPwdButtons"></div>
</div>
<div class="cartsAddAccountTableColumn">
<div id="ldapPwdAreaCancel" class="cartsChgPwdButtons"></div>
</div>
</div>
<div id="ldapPwdAreaStatus"></div>
</div>
</center>
</body>
</html>


utils.js:


define([
"dijit/registry",
"dojo/dom",
"dojo/request",
"dojo/dom-construct",
"dojo/json",
"dojo/date",
"dojo/date/locale",
"dijit/form/Button",
"dojo/dom-style",
"dojo/dom-attr",
"dijit/ConfirmDialog",
"dojo/on",
"dijit/form/TextBox",
"dojo/Deferred"
], function(registry, dom, request, domConst, json, date, locale, Button, domStyle, ConfirmDialog, on, TextBox, Deferred) {

  return {

  /* This function will make sure that the user entered a user name into the */
  /* User Name text box. If not, an error will be displayed on the page. */
  validateUserEntered: function() {
  var dfd = new Deferred();
  if (!registry.byId("username").get("value")) {
    console.log("User name not entered");
    dfd.reject("fail");
  }
  else {
  console.log("User name entered");
  console.log(dfd);
  dfd.resolve("success");
  }
  return dfd;
  }
}
});



From: "Stephen Gevers" <[hidden email]>
To: [hidden email]
Sent: Tuesday, March 10, 2015 3:55:33 PM
Subject: Re: [Dojo-interest] pwCheck function in PasswordValidator

So I looked at your fiddle.  There is no username field in the HTML, so registry.byId(‘username’) should return null.  The next thing I noticed is that if you fail, you return false.  Remember, you can’t run .then() on the return from validateUserEntered if you don’t return a promise (Deferred).  Finally, your <script type=“dojo/on”> is referencing a global function that doesn’t exist.  You need to get away from that and assign that handler inside of a require so that you can have access to the function in the define.

On Mar 10, 2015, at 2:16 PM, Harry Devine <[hidden email]> wrote:



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
12