PDA

View Full Version : Saving Prefrences on a Dashcode Widget




Avizzv92
Feb 25, 2009, 07:29 PM
I'm working on a widget and I need it too save the preferences chosen by the user regardless if the computer was restarted or the widget was closed.

I'm using this document as reference http://developer.apple.com/documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/Preferences.html
(http://developer.apple.com/documentation/AppleApplications/Conceptual/Dashboard_ProgTopics/Articles/Preferences.html)

This is something I put together quickly to test the code, but Its not saving the value of the popup when restarted. What would be wrong with it, and sorry if this is a fairly novice question.

function load()
{
dashcode.setupParts();

if(window.widget)
{
var popupValue = widget.preferenceForKey(popupValue);
}
}

//When the popup value has been changed, it should save the value
function myChangeHandler(event)
{
var popupValue = document.getElementById("popup");
popupValue = popupValue.value;

if(window.widget)
{
widget.setPreferenceForKey(popupValue);
}
}



kainjow
Feb 26, 2009, 08:47 PM
Well first off setPreferenceForKey takes two arguments, and you're passing it one. Second, you're passing preferenceForKey a variable that has yet to be defined.

Try this (untested):
var popupValue = widget.preferenceForKey("popupValue");

...

widget.setPreferenceForKey(popupValue, "popupValue");

Avizzv92
Feb 27, 2009, 02:45 PM
Thanks for your assistance, I made the alterations you suggested and still seems to be having a problem of not saving the value.

function load()
{
dashcode.setupParts();

if(window.widget)
{
var popupValue = widget.preferenceForKey("popupValue");
}
}

//When the popup value has been changed, it should save the value
function myChangeHandler(event)
{
var popupValue = document.getElementById("popup");
popupValue = popupValue.value;

if(window.widget)
{
widget.setPreferenceForKey(popupValue, "popupValue");
}
}

kainjow
Feb 27, 2009, 09:42 PM
You're saving the popup value but never setting it...

Avizzv92
Feb 28, 2009, 01:27 PM
Okay, I got it working now, thanks for your help!