DOM 12 error when using grid.setStyle with latest FireFox

Code that works just fine in IE and Firefox up to version 20, is not breaking after upgrading to FireFox 21. Also, same issue is happening with Google Chrome 26.

The exception is:

An invalid or illegal string was specified" code: “12” nsresult: “0x8053000c (SyntaxError)” location: "http://localhost/app/codebase/dhtmlxgrid.js Line: 287

I have narrowed it down to the .setStyle api… If I comment it out, it works fine. If I pass in “” for the styles, it works fine. Any other value causes this issue:

// Works in IE, FF 20, fails in FF 21 and Google Chrome
rulegrid.setStyle("", “”, “background-color:#fff8e2;”, “”);

// Works everywhere
rulegrid.setStyle("", “”, “”, “”);

So, obviously there is something that dhtmlxgrid.js is doing that the later versions of the browsers doesn’t like!

Please advise… this is a blocking issue for us!

Unfortunately the issue cannot be reproduced locally the pointed method works well for us in FF 21, Chrome 26.
If issue still occurs - please, provide us with a complete demo where, the issue can be reconstructed.
Here you can find a tutorial:
docs.dhtmlx.com/doku.php?id=othe … leted_demo

I’m hoping this will be pretty simple to figure out… I’ve isolated it down to dhtmlxgrid’s setStyle function, specifically the code segment shown below (I formatted the code for readibility):

For the IE browser, it goes down the “then” path, which works fine. For other browser types, the “else path”, which add ‘( { mystyle stuff } )’ around the style string, which throws the exception.

I’m thinking that this was necessary at one point for older browsers, but now with the latest FF (and Chrome by the way), it is throwing an exception.

		for ( var i = 0; i < prefs.length; i++)
			if (this.ssModifier[i]) {
				if (_isIE)
					document.styleSheets[0].addRule(prefs[i],
							this.ssModifier[i]);
				else {
					document.styleSheets[0].insertRule(prefs[i]
					  + (" {" + this.ssModifier[i] + " };"),
					 document.styleSheets[0].cssRules.length);
				}
			}

The exact style strings that I’m trying to use are:

   var gridHeaderStyle = "font-family:Arial;font-size:11px;font-weight:bold;color:#365d9f;";
   var gridBodyStyle = "font-family:Arial;font-size:11px;color:black;";
   var gridSelectedCellStyle = "background-color:#fff8e2;"; 
   var gridSelectedRowStyle = "background-color:#fff8e2; border-color:#5286c8; border-width:1px;";

Then, later in my code I apply the style when setting up the grid:

searchResultsGrid.setStyle(gridHeaderStyle, gridBodyStyle, gridSelectedCellStyle, gridSelectedRowStyle);

I am using //v.2.6 build 100722 of dhtmlxgrid.js

Please, try to update the version of your dhtmlxgrid.

Can you attach the latest version of dhtmlxgrid.js so i can see if this issue is resolved?

I am also on v2.6 and have DHTMLX grid failing in Firefox 21. It worked fine in Firefox 20. I have not debugged the cause yet but guessing it is the same.

I am also using //v.2.6 build 100722 of dhtmlxgrid.js. Is there a patch or fix you can provide us?

Please, try to update the version of your dhtmlxgrid.

I am using Pro version. how do I get the upgrade?

Dear colleagues,

because i got the same problem as “mshaffer” and other’s here i started a little debugging session and figured out following problem.

The following code-sequence is faulty:

for ( var i = 0; i < prefs.length; i++)
             if (this.ssModifier[i]) {
                if (_isIE)
                   document.styleSheets[0].addRule(prefs[i],
                         this.ssModifier[i]);
                else {
                   document.styleSheets[0].insertRule(prefs[i]
                     + (" {" + this.ssModifier[i] + " };"),
                    document.styleSheets[0].cssRules.length);
                }
             }

The Problem occures exactly here:

document.styleSheets[0].insertRule(prefs[i]+ (" {" + this.ssModifier[i] + " };"), document.styleSheets[0].cssRules.length);

Results in (FF 21): [Exception… “An invalid or illegal string was specified” code: “12” nsresult: “0x8053000c (SyntaxError)” location: “”]

Change it to:

document.styleSheets[0].insertRule(prefs[i]+ (" {" + this.ssModifier[i] + " }"), document.styleSheets[0].cssRules.length); (removing the semicolon) seems to resolve the problem.
Results in (FF 21): Returned Integer of insertion of the rule - should work :slight_smile:

Kind regards,
Inquisito

Well, for addition here a screen of the debugging session.

The returned 661 is the index of the last inserted rule (document.styleSheets[0].cssRules[661])
Or any other integer you got… :wink:

Dear Inquisito:

THANK YOU for debugging this!! It fixed our issue as well.

Resolved in:
viewtopic.php?f=2&t=30157&start=10

THANKS to Inquisito for debugging it!

i am glad to hear that.
You are welcome, mshaffer.

Best regards,
Inquisito