Skip to main content
Dmitriy K.
Known Participant
September 9, 2021
Answered

App.response and null

  • September 9, 2021
  • 2 replies
  • 811 views

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 has been closed for replies.
Correct answer Test Screen Name

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

2 replies

try67
Community Expert
Community Expert
September 9, 2021

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

try67
Community Expert
Community Expert
September 9, 2021

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

 

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

Dmitriy K.
Known Participant
September 9, 2021

Once again, many thanks!

Test Screen NameCorrect answer
Legend
September 9, 2021

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

Dmitriy K.
Known Participant
September 9, 2021

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 ();

try67
Community Expert
Community Expert
September 9, 2021

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