When a widget preference == true (or false)
Thursday, January 7, 2010 10:44:38 AM
So say if a checkbox is checked you want a preference value to be TRUE, otherwise FALSE. In my case the code looked like that:
var excludeSVGZ = false;
$('input#excludeSVGZ').change(function(e){
excludeSVGZ = $(this).attr('checked'); // The value is either TRUE or FALSE
widget.setPreferenceForKey(excludeSVGZ, 'excludeSVGZ');
});
And when you need to use the preference you could do something like that:
if (excludeSVGZ){
// Do stuff
}
And this condition will always be TRUE. I've spent quite a bit of time to figure out what's the matter to find that everything was quite easy!
The value is saved as a string, so effectively when you check if (excludeSVGZ){...}, excludeSVGZ will be equal to strings 'true' or 'false' and not to boolean TRUE and FALSE, and thus the condition will always result in TRUE. So to know if a checkbox was checked use this:
if (excludeSVGZ === "true"){
...
}







