Copy link to clipboard
Copied
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.
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();
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
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.