[JS][ScriptUI] Keeping invalid EditText active
- October 28, 2009
- 1 reply
- 2866 views
Hi all,
I have a problem with validating EditText fields.
I got the onChange event handler right.
I got the routine that the textfield falls back to its previous value if the validating test is not met.
Where I fail is that I think the field should stay active as long as the user hasn't entered a valid value.
This is my code so far:
var win = new Window("dialog", "validate");
win.et1 = win.add("edittext", undefined, "0");
win.et2 = win.add("edittext", undefined, "1");
win.et1.characters = 10;
win.et2.characters = 10;
win.et1.fallback = "0";
win.et2.fallback = "1";
win.doneButton = win.add("button",undefined , "Close");
win.et1.onChange = check;
win.et2.onChange = check;
function check() {
if (isNaN(Number(this.text))) {
alert("Type in a number");
this.text = this.fallback;
this.active = true;
}
this.fallback = this.text;
};
win.doneButton.onClick = function () {
win.close();
};
win.center();
win.et2.active = true;
win.show();
(also see enclosed zip)
The function "check" tries to set the fields "active" to true. But it seems that the function is called before the field is deactivated, so this doesn't do anything.
Is this possible?
A different approach I pondered is to not validate fields on change but when th OK button is clicked and then activate the appropriate field(s). But for this I would have to abort the OK-click.
I think this should be possible but I do not know how.
Thank you
Gerald