简体   繁体   中英

'dijit.form.Form' is null or not an object in IE and regex doesn't work

I am getting an error in IE and also the regular expression part of dojo.form.ValidationTextBox fails no matter what in any browser. What am I doing wrong here? I am loading the library through Google API. Below is my code, if you can help that would be awesome. I am wondering if this is a bug with the library itself.

if (typeof(djConfig)=='undefined') {
    djConfig = {
        isDebug: false,
        parseOnLoad: true
    };
}

if (document.location.protocol=='https:') {
    djConfig.modulePaths={
        "dojo":"https://ajax.googleapis.com/ajax/libs/dojo/1.5.0/dojo",
        "dijit":"https://ajax.googleapis.com/ajax/libs/dojo/1.5.0/dijit",
        "dojox":"https://ajax.googleapis.com/ajax/libs/dojo/1.5.0/dojox"
    };
}

google.setOnLoadCallback(function() {
    dojo.require("dijit.form.Form");
    dojo.require("dijit.form.ValidationTextBox");
    dojo.require("dojox.validate.regexp");

    dojo.addOnLoad(function() {
        var newsletterForm = new dijit.form.Form({
            action: '/newsletter.cfm',
            method: 'post',
            target: '_blank'
        }, dojo.byId('newsletter-form'));

        var newsletterEmail = new dijit.form.ValidationTextBox({
            invalidMessage: 'Please double-check your email address',
            promptMessage: 'Enter your email address', 
            regExp: '^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$',
            required: true,
            tooltipPosition: 'below'
        }, dojo.byId('newsletter-email'));
    });
});

google.load('dojo', '1.5');

Here is the answer guys. Apparently Dojo developers are not too keen on usage for Internet Explorer. You must add setTimeout and create an init function inside there, at least that is what I did.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM