Copy link to clipboard
Copied
Just testing this basic dialog.
The edit text should filter out the non-number characters or prevent them from being displayed in the editText box. You can see that the actual function does filter out the non-number characters but the editText box itself still displays the typed characters as is. It will only display the final filtered text once the editText loses focus.
Seems to work as intended in Photoshop and AfterEffect, just not in Illustrator.
Is this me or does it work fine for anyone else?
var w = new Window ('dialog');
w.group = w.add ('group');
var st = w.group.add ('statictext {text: "Enter a number:"}');
w.input = w.group.add ('edittext {characters: 10, active: true, justify: "right"}');
w.buttons = w.add ('group {alignment: "right"}');
w.ok = w.buttons.add ('button {text: "OK", enabled: true}');
w.buttons.add ('button {text: "Cancel"}');
w.input.onChanging = function ()
{
this.text = this.text.replace(/[^0-9,\.\s]/g, "");
st.text = this.text;
}
w.show();
Copy link to clipboard
Copied
I'm using CS6 and the editText box displays only numbers while typing (even if they're added right to left).
Copy link to clipboard
Copied
I should've specified that i'm using Illustrator 2020 and also tried it in 2022 and it's the same behaviour.
Copy link to clipboard
Copied
it doesn't work on CC2022 either, but tapping into the keydown event seems to do the trick. It also doesn't work very well in the ESTK but it works ok in Illustrator.
// type number only
// https://community.adobe.com/t5/illustrator-discussions/illustrator-onchaging-event-doesn-t-update-the-active-edittext/td-p/13191475
var w = new Window ('dialog');
w.group = w.add ('group');
var st = w.group.add ('statictext {text: "Enter a number:"}');
w.input = w.group.add ('edittext {characters: 10, active: true, justify: "right"}');
w.buttons = w.add ('group {alignment: "right"}');
w.ok = w.buttons.add ('button {text: "OK", enabled: true}');
w.buttons.add ('button {text: "Cancel"}');
w.input.addEventListener ('keydown', editKeyboardHandler, false);
function editKeyboardHandler (event) {
//$.writeln (event.keyName);
if ( (event.keyName >= '0' && event.keyName <= '9' ) || event.keyName == "Backspace" || event.keyName == "Right" || event.keyName == "Left" || event.keyName == "Delete") {
//$.writeln (event.keyName);
}
else {
//$.writeln(event.keyName);
event.preventDefault();
}
}
w.show();
Copy link to clipboard
Copied
thanks,
I only recently started to do script for illustrator and coming from after effects the keydown event handler doesn't always fire so I abandonded its use. I guess it seems to work fine in Illustrator. It appears that each software has its own quirks.