I Cant Save Script UI Setting using Script Labels

Enthusiast ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Hello Experts, please help me to identify the problem, it doesnt save user entries when selecting from dropdown index!, i dont know what wrong i do?! , its my first time trying to save user setting from UI, here is the simple code :

//Save User UI Setting
var savedUISettings = eval(app.extractLabel("usersettings"));

//Simple Dialog
var doc = app.documents[0];
var w = new Window ("dialog");
w.preferredSize.width = 320;
w.text = "Select Currency";


var myBinding = [
    "Ignore", 
    "Right to Left", 
    "Left to Right"
                        ];   
                             
var myCurrecy = [
            "$",
            "£",
            "€",
            "¥"
                        ]; 
                             
var myTitle = w.add ("statictext", undefined, "Select Your Binding and Currenc :");
var myDropdown1 = w.add ("dropdownlist", undefined, myBinding);
var myDropdown2 = w.add ("dropdownlist", undefined, myCurrecy);

myDropdown1.selection = 1;
myDropdown2.selection = 3;

//Buttons
var buttons = w.add ("group")
buttons.add ("button", undefined, "OK");
buttons.add ("button", undefined, "Cancel");

var a = w.show()
if(a == 2){
      exit(0);
        // Save UI User Settings
        var userChoice = {
        myDropdown1 : myDropdown1.selection,
        myDropdown2 : myDropdown2.selection,
        }
        app.insertLabel("usersettings", userChoice.toSource());
}

 

Best
M.Hasanain
TOPICS
Scripting

Views

75

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 12, 2022 Aug 12, 2022

Here's how I would do it: 

//Save User UI Setting

var savedUISettings = eval(app.extractLabel("usersettings"));
if (!savedUISettings) {
    savedUISettings = [0,0];
}

//Simple Dialog
var doc = app.documents[0];
var w = new Window ("dialog");
w.preferredSize.width = 320;
w.text = "Select Currency";


var myBinding = [
    "Ignore", 
    "Right to Left", 
    "Left to Right"
];   
                             
var myCurrecy = [
            "$",
            "£",
            "€",
            "¥"
]
...

Likes

Translate

Translate
Community Expert ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Here's how I would do it: 

//Save User UI Setting

var savedUISettings = eval(app.extractLabel("usersettings"));
if (!savedUISettings) {
    savedUISettings = [0,0];
}

//Simple Dialog
var doc = app.documents[0];
var w = new Window ("dialog");
w.preferredSize.width = 320;
w.text = "Select Currency";


var myBinding = [
    "Ignore", 
    "Right to Left", 
    "Left to Right"
];   
                             
var myCurrecy = [
            "$",
            "£",
            "€",
            "¥"
]; 
                             
var myTitle = w.add ("statictext", undefined, "Select Your Binding and Currenc :");
var myDropdown1 = w.add ("dropdownlist", undefined, myBinding);
var myDropdown2 = w.add ("dropdownlist", undefined, myCurrecy);

myDropdown1.selection = savedUISettings[0];
myDropdown2.selection = savedUISettings[1];

//Buttons
var buttons = w.add ("group")
buttons.add ("button", undefined, "OK");
buttons.add ("button", undefined, "Cancel");

if (w.show()) {
    var userSettings = [myDropdown1.selection.index, myDropdown2.selection.index];
    app.insertLabel("usersettings", (userSettings.toSource()));
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

LATEST

@brianp311 , That was smart!, Thanks a lot for your help, i wish you a great day

Best
M.Hasanain

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines