Where Are With SP-TextField Input Event?

API2
Manifest 5
PS Min Version 23.3

Question:
I know there were some issues using .addEventListener(“input” for tracking what’s been entered in the text box.

Where are we now with this, is it safe to use .addEventListener(“input” ?

@kerrishotts may be able to throw some light on this

Thanks

Are these the issues you’re referring to? (UXP 5.5.1 had an issue w/ sp-text-field's change event, not the input event.)

If so, they were fixed in the following UXP release. (UXP 5.6)

Since you’re using API2 & Manifest v5 w/ minVersion of 23.3, you should be fine, since that’s UXP 6.0.2.

I was referring to this post @kerrishotts

Per the thread, the issue is not the input event itself, but using it in conjunction with sp-slider (or other similar controls) while calling executeAsModal inside the event handler. executeAsModal was throwing because it thought Ps was in a modal state not already created by the plugin. PS 23.4 will address that issue.

input events that don’t use executeAsModal are fine wherever they are. Further, for keyboard events, executeAsModal is safe inside of event handlers – (see following code) – just that for 23.3 you should avoid them whenever the mouse button might be down (or catch the resulting error).

const exeModal = require('photoshop').core.executeAsModal;
const batchPlay = require("photoshop").action.batchPlay;

const setTest = async function (value) {
  try {
    await exeModal(() => {
        /* if this were a sp-slider, this wouldn't be logged, because
           executeAsModal would throw. */
        console.log("hi");
    }, {});
  } catch (e) {
    console.error(e)
  }
};

/* assumes <sp-textfield id="testInput"></sp-textfield> in the HTML */
document.getElementById("testInput").addEventListener('input', async (evt) => {
  await setTest(evt.target.value);
});

I just tested the above in Ps 23.3, and executeAsModal works just fine as part of an input event from sp-textfield. It will fail when called from sp-slider because the mouse button has put Ps into a modal state. But keyboard events don’t have the same result.

TL;DR: You can use input events on sp-textfield in Ps 23.x.