Skip to main content
Inspiring
April 25, 2020
Answered

ScriptUI field validation

  • April 25, 2020
  • 2 replies
  • 2827 views

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

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

 

 

This topic has been closed for replies.
Correct answer Geppetto Luis

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();

 

2 replies

Geppetto Luis
Geppetto LuisCorrect answer
Braniac
April 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();

 

Inspiring
April 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?

Geppetto Luis
Braniac
April 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();

 

Braniac
April 25, 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.