ScriptUI: Always honor Cancel/Esc in onClose validations

When you need to validate user input in an edittext field, it’s not enough to do so in its onChange event — you must also validate it in the dialog’s onClose. It’s the only way to stop the dialog from closing after a click on the OK button, so that the user has a chance to correct his input. But what if that close event occurred because of an explicit user action to simply dismiss the dialog, like clicking the Cancel button?

Please just let me Cancel

By default, it seems that the close event does not distinguish between an “OK” close and a “Cancel” close. This can be problematic in input validations, because if your validator is designed to prevent the dialog from closing upon detection of faulty input, it should absolutely not do so in the event of an explicit “Cancel” (or Esc) close.
Continue reading