Unable to display jquery alert from dojo template

245 Views Asked by At

I'm working with Dojo-1.9.1 and trying to build a templatized form for our application. I'm using noty to display an error alert when form validation fails. Invoking noty works when I directly use within the template like this:

<form data-dojo-attach-point="formNode" data-dojo-type="dijit/form/Form"
    enctype="application/x-www-form-urlencoded" action=${submitUrl} method="post">
    <script type="dojo/on" data-dojo-event="submit">
        if(!this.validate()){
            noty({
        text: '${messages.invalidForm}',
        type: 'error',
        modal: true,
        timeout: 2000, // false, to wait for user click
        closeWith: ['click', 'hover'], // ['click', 'button', 'hover']
        }); // works
        return false;
        }
        return true;
        </script>
<!-- other fields -->
</form>

However noty fails to show when created within onSubmit method like this:

<form data-dojo-attach-point="formNode" data-dojo-type="dijit/form/Form"
    enctype="application/x-www-form-urlencoded" action=${submitUrl} method="post" data-dojo-attach-event="onSubmit:handleSubmit">

</form>

//Within the template.js
handleSubmit: function() {
 if(!this.formNode.validate()) {
     noty({text:...}); //fails to come up
     return false;
 }
 return true;
}

dojoConfig:
// ... preceding dojo packages
{ name: "jquery", location: "lib", main: "jquery-1.10.2.min" },
{ name: "noty", location: "lib", main: "jquery.noty.packaged.min" }

It fails to come up in the console too. I guess I've correctly AMD'd the libraries since it works in the first instance. Could anyone please point out any missing links in my implementation. Thanks.

1

There are 1 best solutions below

0
On

Answering my own question. I got this working by loading noty as a non-amd file:

//Within the template.js    
define([..., 'resources/js/lib/jquery.noty.packaged.min.js'], function(...) {

handleSubmit: function() {
 if(!this.formNode.validate()) {
     noty({text:...}); //fails to come up
     return false;
 }
 return true;
}
    })