GM_config

By JoeSimmons Last update Dec 19, 2013 — Installed 1,175,613 times.

Boolean handling error

in
Subscribe to Boolean handling error 4 posts, 3 voices



sizzlemctwizzle Scriptwright
FirefoxMacintosh

I noticed you changed this line:

passed_values[i] = stored[i] || settings[i].default || '';

to this:
passed_values[i] = (stored[i]===false && settings[i].default===true)? false : (((typeof stored[i]=='number'||typeof stored[i]=='string')?stored[i].toString():false)||settings[i].default||'');

This cause the error that if you have a checkbox that's default value is false, it can't be changed to true. It can be saved as true, but your current code ends up giving it a value of '' which is then evaluated as false. I suggest a change of code to:

passed_values[i] = (stored[i]===false && settings[i].default===true)? false : (((typeof stored[i]=='number'||typeof stored[i]=='string'||typeof stored[i]=='boolean')?stored[i]:false)||settings[i].default||'');
The toSource isn't need anyway because we already store the values correctly.

p. s. This error took me forever to trackdown lol. I went through testing several parts of the code.

 
JoeSimmons Script's Author
FirefoxWindows

Thanks, updated it.

 
Arthaey Angosii Scriptwright
FirefoxWindows

When I use type="checkbox", I cannot save a value different from the default.

If I set the default to true, the value will always be true. If I set the default to false, the value will always be false. It does not update when you toggle the checkbox and click Save.

 
JoeSimmons Script's Author
FirefoxWindows

Hmm, I'll have a look.