Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Avizzv92

macrumors regular
Original poster
Mar 23, 2008
172
0
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


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.

Code:
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

Moderator emeritus
Jun 15, 2000
7,958
7
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):
Code:
var popupValue = widget.preferenceForKey("popupValue");

...

widget.setPreferenceForKey(popupValue, "popupValue");
 

Avizzv92

macrumors regular
Original poster
Mar 23, 2008
172
0
Thanks for your assistance, I made the alterations you suggested and still seems to be having a problem of not saving the value.

Code:
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");
}
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.