Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#17183 closed defect (invalid)

script type="dojo/require" in template fails on IE7/8

Reported by: neville1355 Owned by:
Priority: undecided Milestone: tbd
Component: Parser Version: 1.9.0
Keywords: Cc:
Blocked By: Blocking:

Description

I opened a bug previously on the matter below: https://bugs.dojotoolkit.org/ticket/16609

This was supposedly fixed by moving the script block to the bottom of the page but it seems that this bandaid fix is no longer working.

It looks like script blocks are being stripped in IE7/8 regardless of position when they're contained in templates. The offending line looks like domConstruct.toDom(string). This causes the template parser to fail as an aliased function I refer to was stripped when the script block was removed.

We are currently using 1.8.3, but I was able to recreate the bug on 1.9.

Below is the template which uses dojo/require:

<span>
    <span data-dojo-type="dojox/mvc/Output" data-dojo-props="value:func('Test')"></span>
    <script type="dojo/require">func:"./MyFunc.js"</script>
</span>

The module MyFunc?.js is a simple function that returns whatever is passed as a parameter

define([],
       function()
	{
		return function(value){return value;}
	});

On IE9+, Chrome and FF my test page display "Text" correctly. One IE7-8, the following error is logged:

dojo/parser::parse() errorError: TypeError: The value of the property 'func' is null or undefined, not a Function object in data-dojo-props='value:func('Test')' 

Attachments (3)

Test dojo require.html (922 bytes) - added by neville1355 7 years ago.
Main test page to load
ParentWidget.js (736 bytes) - added by neville1355 7 years ago.
Sample widget that is being required by the main page
MyFunc.js (78 bytes) - added by neville1355 7 years ago.

Download all attachments as: .zip

Change History (7)

Changed 7 years ago by neville1355

Attachment: Test dojo require.html added

Main test page to load

Changed 7 years ago by neville1355

Attachment: ParentWidget.js added

Sample widget that is being required by the main page

Changed 7 years ago by neville1355

Attachment: MyFunc.js added

comment:1 Changed 7 years ago by neville1355

This is a major problem for us as we heavily lean on templates and IE8 still has a major portion of the total browser market share.

comment:2 Changed 7 years ago by bill

Component: GeneralParser
Resolution: invalid
Status: newclosed
Summary: script type="dojo/require" fails on IE7/8script type="dojo/require" in template fails on IE7/8

You can't put <script type="dojo/require"> inside a template. You should just require the needed modules in ParentWidget.js.

Actually, it's strange to put any <script> tags inside a template.

comment:3 Changed 7 years ago by neville1355

The dojo/require tags are needed to give scope to required functions in the template - e.g. dojox/mvc/at.

How else are you supposed to accomplish this? Require the modules and then call lang.setObject()? That seems like pretty bad design. The view/template should be able to alias functions that it uses to separate view and business logic.

http://dojotoolkit.org/reference-guide/1.9/dojo/parser.html

As specified here, the parser supports this syntax regardless and _WidgetsInTemplateMixin runs the parser.

comment:4 in reply to:  3 Changed 7 years ago by bill

Well, lang.setObject() will do the same thing as <script type="dojo/require">, i.e. create a global variable, but I'm not recommending either of those approaches.

Probably what you want is for your template to reference a function within your main ParentWidget? instance, in which case you would use this, something like <span data-dojo-type="dojox/mvc/Output" data-dojo-props="value: this.func(\'Test\')"></span>. Or, stop trying to do so much in the template, and do it programatically.

Note: See TracTickets for help on using tickets.