• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Can only use Dialog box with input text once

Explorer ,
Nov 15, 2022 Nov 15, 2022

Copy link to clipboard

Copied

Hey! I am creating a dialog window in an Adobe Photoshop Script to search my company's website, and I have run into an issue with the Text input field. I have the text input field working just fine the first time I run it, but if I try to change the value again it returns undefinied and if I try to run it a third time it does nothing. 

I think it is just overriding the edittext property. I have used some code from this forum https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-ui-text-field-input/m-p/128995...
but I am still struggling to get a reusable text field. 
I just made the function an alert so that I wasn't opening a new chrome tab everytime I tested different code.
Here is the snippet of my code 

var panelWebsiteSearch = dialog.add("panel", undefined, undefined, {name: "Website Search"}); 
    panelWebsiteSearch.text = "Website Search"; 
    panelWebsiteSearch.preferredSize.width = (dialog.preferredSize.width-50); 
    panelWebsiteSearch.orientation = "row"; 
    panelWebsiteSearch.alignChildren = ["left","top"]; 
    panelWebsiteSearch.spacing = 10; 
    panelWebsiteSearch.margins = 10; 
    panelWebsiteSearch.alignment = ["left","top"]; 

var statictext1 = panelWebsiteSearch.add("statictext", undefined, undefined, {name: "statictext1"}); 
    statictext1.text = "Search https://www.website.com/"; 
    statictext1.alignment = ["left","top"]; 
var edittext1 = panelWebsiteSearch.add('edittext {properties: {name: "edittext1"}}'); 
    edittext1.text =  "Search Keywords";
    edittext1.preferredSize.width = 300; 
    edittext1.alignment = ["Right","top"];
    edittext1.value = edittext1; 

var buttonWebsiteSearch = panelWebsiteSearch.add("button", undefined, undefined, {name: "buttonWebsiteSearch"}); 
    buttonWebsiteSearch.text = "Search"; 
    buttonWebsiteSearch.alignment = ["right","center"];
    buttonWebsiteSearch.addEventListener('click', function (){
        edittext1.value = edittext1;
        edittext1 = edittext1.text;
        alert (edittext1);
        //system('start https://www.website.com/search/'+ edittext1 + '.html');
    },
        false);

 Thanks!

TOPICS
Actions and scripting

Views

694

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 , Nov 15, 2022 Nov 15, 2022

 

buttonWebsiteSearch.addEventListener('click', function (){
        alert (edittext1.text);
        //system('start https://www.website.com/search/'+ edittext1.text + '.html');
},

 

¯\_(ツ)_/¯

Likes

Translate

Translate
Community Expert ,
Nov 15, 2022 Nov 15, 2022

Copy link to clipboard

Copied

 

buttonWebsiteSearch.addEventListener('click', function (){
        alert (edittext1.text);
        //system('start https://www.website.com/search/'+ edittext1.text + '.html');
},

 

¯\_(ツ)_/¯

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
Explorer ,
Nov 15, 2022 Nov 15, 2022

Copy link to clipboard

Copied

LATEST

Worked perfectly, thanks! 

Here is the code for anyone interested in the future. 

var dialog = new Window("dialog", undefined, undefined, {resizeable: true}); 
    dialog.text = "Reference Images"; 
    dialog.preferredSize.width = 700; 
    dialog.preferredSize.height = 700; 
    dialog.orientation = "column"; 
    dialog.alignChildren = ["left","top"]; 
    dialog.spacing = 10; 
    dialog.margins = 16; 


 var activeFileName = app.activeDocument.name.split("_")[0]  
// PANEL1
// ======
var panelWebsiteSearch = dialog.add("panel", undefined, undefined, {name: "Website Search"}); 
    panelWebsiteSearch.text = "Website Search"; 
    panelWebsiteSearch.preferredSize.width = (dialog.preferredSize.width-50); 
    panelWebsiteSearch.orientation = "row"; 
    panelWebsiteSearch.alignChildren = ["left","top"]; 
    panelWebsiteSearch.spacing = 10; 
    panelWebsiteSearch.margins = 10; 
    panelWebsiteSearch.alignment = ["left","top"]; 

var statictext1 = panelWebsiteSearch.add("statictext", undefined, undefined, {name: "statictext1"}); 
    statictext1.text = "Search https://www.yourwebsite.com/"; 
    statictext1.alignment = ["left","top"]; 
var edittext1 = panelWebsiteSearch.add('edittext {properties: {name: "edittext1"}}'); 
    edittext1.text =  "Search Keywords";
    edittext1.preferredSize.width = 300; 
    edittext1.alignment = ["Right","top"];
     

var buttonWebsiteSearch = panelWebsiteSearch.add("button", undefined, undefined, {name: "buttonWebsiteSearch"}); 
    buttonWebsiteSearch.text = "Search"; 
    buttonWebsiteSearch.alignment = ["right","center"];
    buttonWebsiteSearch.addEventListener('click', function (){
        var sku = edittext1.text
        sku = sku.replace(/\s+/g, '-').toLowerCase();   
        alert (sku)
       system('start https://www.yourwesbite.com/search/'+ sku + '.html');
},)

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