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

ScriptUI field validation

Engaged ,
Apr 24, 2020 Apr 24, 2020

Can a scriptUI dialog check if the value entered in the text field is valid?

Screen Shot 2020-04-24 at 5.53.59 PM.png

For example, if the field is empty, display an alert that the field can not be empty.

Screen Shot 2020-04-24 at 5.54.07 PM.png

 

 

TOPICS
Actions and scripting
2.8K
Translate
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

Advocate , Apr 25, 2020 Apr 25, 2020

See this if it's okay for you.

var regExp = new RegExp();
win = new Window("dialog", "TEST",undefined);

var textInput =win.add("edittext", undefined, "TEXT");
textInput.characters = 20;
textInput.active = true;

closeBtn =win.add("button", undefined, "CLOSE");

closeBtn.onClick = function () {
if (textInput.text == "")
alert("ALERT !!!\nEMPTY EDITTEXT?");
else {
win.hide();
}
}

win.show();

 

Translate
Adobe
LEGEND ,
Apr 24, 2020 Apr 24, 2020

Yes, use edittext.onChanging() event to test as you type and edittext.onChange() to check when you leave the field. Put your validation code in another function that you call.

Translate
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
Advocate ,
Apr 25, 2020 Apr 25, 2020

See this if it's okay for you.

var regExp = new RegExp();
win = new Window("dialog", "TEST",undefined);

var textInput =win.add("edittext", undefined, "TEXT");
textInput.characters = 20;
textInput.active = true;

closeBtn =win.add("button", undefined, "CLOSE");

closeBtn.onClick = function () {
if (textInput.text == "")
alert("ALERT !!!\nEMPTY EDITTEXT?");
else {
win.hide();
}
}

win.show();

 

Translate
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
Engaged ,
Apr 25, 2020 Apr 25, 2020

Yes, this solution works. Thank you for providing the sample. Once the alert dialog is closed can the scriptUI insert the original textfiled value TEXT in the empty field?

Screen Shot 2020-04-25 at 10.44.55 AM.png

Translate
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
Advocate ,
Apr 25, 2020 Apr 25, 2020

that's fine.

var regExp = new RegExp();
win = new Window("dialog", "TEST",undefined);

var textInput =win.add("edittext", undefined, "TEXT");
textInput.characters = 20;
textInput.active = true;

closeBtn =win.add("button", undefined, "CLOSE");

closeBtn.onClick = function () {
if (textInput.text == "")
alert("ALERT !!!\nEMPTY EDITTEXT?");
else {
win.hide();
}
 textInput.text = "TEXT";
}

win.show();

 

Translate
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
Engaged ,
Apr 25, 2020 Apr 25, 2020
LATEST

Thank you much, that works. Can the filed focus return to highlight the TEXT in blue after the validation? 

I placed textInput.active = "true" below textInput.text = "TEXT" in the onClick function. But the filed focus does not dispaly.

Translate
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