I like working with alerts but have a simple question to help me go further with them. Here’s an example:
let myAlert = new Alert(); myAlert.title = "title of alert pop up"; myAlert.addTextField("this is field 0"); myAlert.addTextField("this is field 1"); myAlert.addCancelAction("Cancel"); myAlert.addAction("Submit"); await myAlert.present(); const entryOne = myAlert.textFieldValue(0); const entryTwo = myAlert.textFieldValue(1);
If I run this, enter some text in the two text fields and hit ‘Submit’, entryOne & Two are filled.
If I do the same and hit ‘Cancel’, the same happens.
In effect, both of these buttons (as written) just dismiss the Alert and the script continues.
I’d like to stop the script when ‘Cancel’ is pressed, unsurprisingly!
addCancelAction will return the index -1. How do I access that index? Once I know that, a simple if statement should get me what I need.