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

addEventListener - change

Community Expert ,
Jun 26, 2012 Jun 26, 2012

Copy link to clipboard

Copied

I'm trying to learn how the event handlers work.  I set up a simple dialog to use MouseEvents.  I got the "click" event to work but when I try to set an event for "change" nothing happens.  Basiclly with the UI, if you change the selection in the dropdownlist, an alert should pop up sayiing "p2".  This was run on Photoshop CS5.  Is this a bug, or I'm I doing something wrong? Here's the code:

var drop1 = ['one','two','three']

var d

createDlg ()

function createDlg(){

      d = new Window('dialog','test')

            d.p1 = d.add('panel',undefined,'panel 1')

                  d.p1.cbx1 = d.p1.add('checkbox',undefined,'checkbox 1');

                  d.p1.rb1 = d.p1.add('radiobutton',undefined,'radio button 1')

                  d.p1.rb2 = d.p1.add('radiobutton',undefined,'radio button 2')

                  d.p1.etx1 = d.p1.add('edittext',undefined,'edit text one')

                  d.p1.rb1.value = true

            d.p2 = d.add('panel',undefined,'panel 2')

                  d.p2.cbx2 = d.p2.add('checkbox',undefined,'checkbox 2');

                  d.p2.dp1 = d.p2.add('dropdownlist',undefined,drop1);

                  d.p2.dp1.selection = 0

            d.addBtn = d.add('button',undefined,'add')

            d.removeBtn = d.add('button',undefined,'remove')

            d.closeBtn = d.add('button',undefined,'close')

            d.addBtn.onClick = function(){intD(d)}

            d.removeBtn.onClick = function(){removeD(d)}

            d.closeBtn.onClick = function(){d.close()}

      d.show()

      }

function intD(w){

      ScriptUI.events.createEvent('MouseEvent');

      w.p1.addEventListener ('click', p1handler, false);

      w.p2.addEventListener ('click', p2handler, false);

      w.p2.dp1.addEventListener ('change', p2handler, true);

      }

function removeD(w){

      w.p1.removeEventListener ('click', p1handler, false);

      w.p2.removeEventListener ('click', p2handler, false);

      w.p2.dp1.removeEventListener ('change', p2handler, false);     

      }

function p1handler(){

      if(d.p1.rb1.value){d.p1.etx1.text = 'true'}

      else{d.p1.etx1.text = 'false'}

      }

function p2handler(){alert('p2')}

TOPICS
Actions and scripting

Views

1.8K

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
Adobe
Guru ,
Jun 26, 2012 Jun 26, 2012

Copy link to clipboard

Copied

I have found that mouse events don't work correctly for me with Photoshop CS5. The same dialog that fails there works as expected in other Adobe apps that support ScriptUI.

Votes

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
Community Expert ,
Jun 26, 2012 Jun 26, 2012

Copy link to clipboard

Copied

Thanks, Mike.  I'll have to try this on CS6 and see what happens, but we haven't upgraded at work yet to CS6, and I might need this backward compatable for a bit.

Votes

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
New Here ,
May 20, 2015 May 20, 2015

Copy link to clipboard

Copied

And do Adobe have a fix for that???

I mean if the eventlisteners work on the controls why not lauch it from a dialog box at PS start? Is it possible?

Votes

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
New Here ,
Mar 22, 2024 Mar 22, 2024

Copy link to clipboard

Copied

LATEST

the issue persist on Photoshop 25.3.1 (2024)

theDropdownlist has a "selection" property, which give the item selected.

if you change it by code:

dropdown_instance.selection = 0;

then the onChange callback is activated. 

But when a user click on the dropdownlist is not changing the "selection" property and by consecuente, the callback is not triggered. 

it seems something is broken when the UI change the "selection" property.

 

I hope this help to solve this bugs in the future. 

 

Votes

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