views:

49

answers:

1

I am simply trying to read a user's boolean preference in a Google Gadget, but it seems that the preference is never getting saved at all, and I only ever get whatever the default_value is. I've broken this down into a very simple test case. Here is my test gadget spec:

<?xml version="1.0" encoding="UTF-8" ?> 
<Module>
  <ModulePrefs title="Gadget to test bool"> 
  </ModulePrefs>
  <UserPref name="testpref" display_name="Test Boolean Preference" default_value="true" datatype="bool" />
  <Content type="html">
  <![CDATA[
    <script type="text/javascript"> 
        var prefs = new gadgets.Prefs();
        alert(prefs.getBool('testpref'));
    </script>
  ]]>
  </Content>
</Module>

What I expect to see is an alert with true or false in it for whatever the user has chosen in the preferences dialog. However, the user's preferences are completely ignored, not saved, and even my default value isn't shown in the preferences. When I specify true for the default value, the preference checkbox remains unchecked.

What am I missing?

Edit: I am trying to get this working on a Google Apps Google Sites Start Page.

+1  A: 

I tested your sample code in iGoogle and it seems to be working correctly. That is a box can be checked or unchecked and the alert is fired with the correct value.

As far as I know certain types of gadget containers do not allow user preferences - so the gadget that will work in iGoogle will not work correctly in standard Google Sites pages (apart from user customisable-type page).

Another common problem with code "not working" in iGoogle is caching of the gadget code. To force a gadget not to cache add "?nocache" to the gadget URL...

Michal
Thanks Michal. I have been using nocache. You mention that it doesn't work on a Google Sites page... does this apply on a Google Sites Start Page as part of Google Apps as well? Is this documented anywhere? Thanks again for your response.
Brad
I guess I should clarify that in Google sites the only UserPref you can set is when you add a gadget to the page. So a person who is editing the page and adding a gadget can adjust settings on a gadget as specified in UserPref however if another user accesses that page all they will see is a "static" gadget and they will be unable to set any preferences on it - the preferences will default to what the creator of the page set them to. I am not 100% sure what you mean by Google Apps Sites Start page - the page that shows mysites as you login? or the first page of a site you created?
Michal
Brad