Skip to main content
Dmitriy K.
Known Participant
Sep 9, 2021 8:33 AM UTC
Answered

App.response and null

Why, if the input field is empty and the user pressed the OK button, the function is not interrupted and the Else block is processed?

app.addSubMenu({ cName: "Test", cParent: "Help", nPos: 0})
app.addMenuItem({ cParent: "Test", cName: "My_button",  nPos: 2, cExec: "NumberX()", cEnable: "event.rc = (event.target != null);"});

function NumberX() 
{
		Msg = app.response(" ", " ");
		if (Msg == null) {
			app.alert("The user did not enter anything and clicked Ok");
			return;}
		else 
		{	
			app.alert("The user entered some number: " + Msg);
		}			
};

app.trustedFunction(NumberX);

 

This topic is closed to new replies. Start a new post to keep the conversation going.
Test Screen NameCorrect answer
Legend
Sep 9, 2021 8:41 AM UTC

The documentation says app.response returns null if the user clicks Cancel. Your user is not doing this!

7 replies

try67
Community Expert
Community Expert
Sep 9, 2021 8:51 AM UTC

If they click OK and don't enter anything the returned value is an empty string, which is not the same as null.

Translate
try67
Community Expert
Community Expert
Sep 9, 2021 9:13 AM UTC

You can handle both scenarios at the same time, like this:

 

if (Msg == null || Msg=="")

Translate
Dmitriy K.
Known Participant
Sep 9, 2021 9:24 AM UTC

Once again, many thanks!

Translate
Test Screen NameCorrect answer
Legend
Sep 9, 2021 8:41 AM UTC

The documentation says app.response returns null if the user clicks Cancel. Your user is not doing this!

Translate
Dmitriy K.
Known Participant
Sep 9, 2021 8:54 AM UTC

Thank you, now I found it in API 

Tell me how you can handle the OK button? or for this you need to use app.execDialog ();

Translate
try67
Community Expert
Community Expert
Sep 9, 2021 8:59 AM UTC

Just replace null in your code with ""...

Translate