Skip to main content
Inspiring
April 25, 2020
解決済み

ScriptUI field validation

  • April 25, 2020
  • 返信数 2.
  • 2846 ビュー

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.

 

 

このトピックへの返信は締め切られました。
解決に役立った回答 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

Geppetto Luis
Geppetto Luis解決!
Legend
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();

 

Polycontrast作成者
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
Legend
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();

 

Legend
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.