Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

App.response and null

Participant ,
Sep 09, 2021 Sep 09, 2021

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

 

TOPICS
Acrobat SDK and JavaScript
877
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 09, 2021 Sep 09, 2021

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

Translate
LEGEND ,
Sep 09, 2021 Sep 09, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 09, 2021 Sep 09, 2021

Thank you, now I found it in API 

image.png

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 09, 2021 Sep 09, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 09, 2021 Sep 09, 2021

I have already tried this option, but then the Cancel button and closing the window with a cross do not work correctly

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 09, 2021 Sep 09, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 09, 2021 Sep 09, 2021

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

 

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 09, 2021 Sep 09, 2021
LATEST

Once again, many thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines