Message box not appearing - function not functioning!

Avatar

Avatar

SunsV

Avatar

SunsV

SunsV

29-06-2014

Hi there,

newbie here so be kind please!

I have a table in my form with a remove button for each table row - this works fine, but it occurred to me that it would make more sense to bring up a message box warning the user that they are about to delete a table row. I've tried and tried, but whenever I test or save the file nothing now happens when I click the remove button - no warning window appears and the remove button does not remove the row.

Here's my code:

form1.plan.plansub.plantable.planrow.Remove::click - (JavaScript, both)

var cMsg = "Warning: Clicking YES with remove the current entry from your plan";

cMsg += "\n\nDo you want to continue?";

var nRtn = app.alert({

cMsg,2,2,"Warning"});

if (nRtn == 4)

{

  this.parent.parent._planrow.removeInstance(this.parent.index);

}

xfa.form.recalculate(1);

So, I'm probably doing something really obvious - please help!

Sunil

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

_Bruce_Robertson

MVP

Total Posts

1.8K

Likes

268

Correct Answer

372

Avatar

_Bruce_Robertson

MVP

Total Posts

1.8K

Likes

268

Correct Answer

372
_Bruce_Robertson
MVP

30-06-2014

Hi

The messageBox method will return a 4 if the Yes button is clicked, so

 

var button = xfa.host.messageBox("You are about to remove an entry in the plan. Do you wish to proceed?", "Removing Entry!", 2, 2);

if (button == 4)

{

   this.resolveNode('plantable._planrow').removeInstance(this.parent.index);

   if (xfa.host.version < 8) {

     xfa.form.recalculate(1);

   }

}

 

Answers (7)

Answers (7)

Avatar

Avatar

jnicholas330

Avatar

jnicholas330

jnicholas330

29-06-2014

It sounds like there is a error in your code. Turn on the JavaScript debugger in Acrobat and it should give you the error.

Avatar

Avatar

_Bruce_Robertson

MVP

Total Posts

1.8K

Likes

268

Correct Answer

372

Avatar

_Bruce_Robertson

MVP

Total Posts

1.8K

Likes

268

Correct Answer

372
_Bruce_Robertson
MVP

30-06-2014

Your second 2 in the messageBox method means show Yes and No buttons, a 1 would show Ok and Cancel, so the values returned can be;

1 (OK)

2 (Cancel)

3 (No)

4 (Yes)

More info here, Adobe LiveCycle ES3 * messageBox

Avatar

Avatar

SunsV

Avatar

SunsV

SunsV

30-06-2014

MANY many thanks BR001 - that worked!

Just for future reference, the value 4 - where does that come from and what other values can be used?

Sunil

Avatar

Avatar

SunsV

Avatar

SunsV

SunsV

30-06-2014

complete change of tac here:

I've replaced all the code and instead have used the action builder. Unfortunately for messages there are no options to put in if statements. Here's the code:

form1.plan.plansub.plantable.planrow.Remove::click - (JavaScript, both)

xfa.host.messageBox("You are about to remove an entry in the plan. Do you wish to proceed?", "Removing Entry!", 2, 2);

this.resolveNode('plantable._planrow').removeInstance(this.parent.index);

if (xfa.host.version < 😎 {

  xfa.form.recalculate(1);

}

At the moment even if the message box answer is No it still removes the row in its entirety (which I only want to happen if the answer is 'Yes') I'm assuming that this is down to me not having an if statement. Problem is I don't know what I should do at this point. Can someone help?

Avatar

Avatar

SunsV

Avatar

SunsV

SunsV

30-06-2014

I think I've found something.

I've taken the code (above) from an example of buttons that are used in acrobat that I found online - and can be implemented through acrobat pro. The code itself works fine. However, if I open the example file in live cycle and save it, the file no longer works in acrobat pro or reader (despite not editing it in any way). It doesn't work in so much as clicking on the example button that should open a warning box doesn't do anything. Running this file in Apro with the debugger doesn't give an error either.

Could this be that there are differences in the way scripting is implemented in Apro versus LiveCycle? If that's the case I get the impression that I'm not adding something that I need to whereas Apro automatically adds this (which is then subsequently removed when you open it up in LiveCycle)?

Avatar

Avatar

SunsV

Avatar

SunsV

SunsV

30-06-2014

Hi jnicholas,

I have run the file in acrobat pro and I get the message

SyntaxError: invalid object initializer

4:XFA:form1[0]:plan[0]:plansub[0]:plantable[0]:planrow[0]:Remove[0]:mouseUp

I'm a real beginner here and although I can see the logic in scripting I'm not versed in it... not yet anyway. Any help would be gratefully received.

form1.plan.plansub.plantable.planrow.Remove::mouseUp - (JavaScript, client)

var cMsg = "Warning: Clicking YES with remove the current entry from your plan";

cMsg += "\n\nDo you want to continue?";

var nRtn = app.alert({

cMsg,2,2,"Warning"});

if (nRtn == 4)

{ this.parent.parent._planrow.removeInstance(this.parent.index);

}

xfa.form.recalculate(1);

Avatar

Avatar

SunsV

Avatar

SunsV

SunsV

29-06-2014

any help?