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

Clear button should have YES / NO

Community Beginner ,
Sep 18, 2021 Sep 18, 2021

Copy link to clipboard

Copied

-------------------------------------------------------------------------------------------------------------------------------

Clear Form (Mouse Up)

 

When you click the “Clear Form” button a Message box should popup and say:

 

“STOP!

DO NOT clear this form until you saved it under Suspect name; LAST, First & Date.

Do you want to clear this form?”

                                                                                               YES     NO

 

When you click “YES” the form should be cleared and the Message box should close.

When you click “NO” the Message box should close and the form will NOT be cleared

 

Ia there javascript available that can do this? I gave up searching.

Any help would be greatly appreciated by 4,000 cops

TOPICS
JavaScript

Views

4.8K

Translate

Translate

Report

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
2 ACCEPTED SOLUTIONS
Community Expert ,
Sep 18, 2021 Sep 18, 2021

Copy link to clipboard

Copied

Try this as Mouse UP event of "Clear Form" Button:

var x = app.alert("STOP! DO NOT clear this form until you saved it under Suspect name; LAST, First & Date. Do you want to clear this form?", 2, 2);
if(x == 4)
this.resetForm();

View solution in original post

Votes

Translate

Translate

Report

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 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

LATEST

At this line: var y21 = fields.indexOf( "); you are missing " it should be: var y21 = fields.indexOf("");

View solution in original post

Votes

Translate

Translate

Report

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 Beginner ,
Sep 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

What you gave me did not work. OK I just replaced mailDoc with resetForm and a Message box pops up with a RED X in the upper left corner and only an OK button. When I click the OK button nothing happens. Perhaps I did not explain it right so here is a better explanation.

---------------------------------------------------------------------------------------------------------------------

Clear Form (Mouse Up)

 

THIS IS WHAT I AM IN NEED OF AND CANNOT FIND THE CODE TO DO IT

 

When you click the “Clear Form” button a Message box should popup and say:

 

“STOP!

DO NOT clear this form until you saved it under Suspect name; LAST, First & Date.

Do you want to clear this form?”

                                                                                               YES     NO

 

When you click “YES” the form should be cleared and the Message box should close and those fields I have unchecked in Reset-a-form should not be deleted but they are. If I delete Reset-a-form then all the unchecked fields will still be deleted which I do not want.

When you click “NO” the Message box should close and the form will NOT be cleared.

---------------------------------------------------------------------------------------------------------------------

Votes

Translate

Translate

Report

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 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

I told you before (again), that you can not combine a script with other actions. The entire operation needs to be done using code. If you want to only reset certain fields you have to include their names in the resetForm command, like this:

 

this.resetForm(["Text1", "Text2", "Text5"]);

 

This will cause only those three fields to be reset. All other fields will retain their current values.

Votes

Translate

Translate

Report

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 Beginner ,
Sep 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

Sorry you are losing your patience. I said I was new at this. Yes I did list fields. I listed only one field to test it and got this problem:

 

var rFields = ["Detective Analyst"];
var x = app.alert("STOP! DO NOT clear this form until you saved it under Suspect name; LAST, First & Date. Do you want to clear this form?", 2, 2);
if(x == 4)
this.resetForm(rFields);

 

When I click YES in the Message box it deletes the field "Detective Analyst" which is should not. That field should stay and other fields should be cleared.

 

I have been given so many codes none of which worked. Am I trying to do something that javascript is not capable of doing.

Votes

Translate

Translate

Report

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 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

I'm not losing my patience, but it does sometimes seem like you're ignoring the advice you've been given. And it doesn't help that you keep opening new threads for your questions. Try to stick to the ones you've already created.

 

Regarding the code, that is exactly how it should work. If you want to exclude this one field then you have to provide an array that contains the list of all other fields names in the file. There's no option to supply a list of fields to exclude directly.

Votes

Translate

Translate

Report

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 Beginner ,
Sep 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

The form is 10 pages with hundreds of fields. It would be insane to list them all in the script. I'm better off just using reset-a-form and unchecking all the fields in the list of fields which is exactly what I need. Under the bottom I can leave a message to the user that says:

 

       CLEAR FORM

DO NOT Clear Form Until

Saved Under Suspect Name

Clicking Button Will Delete ALL

 

At least it will not delete the fields I have unchecked in reset-a-form. They will just have to be careful before clicking "Clear Form"  Unfortunate there is not an easier way to do this.

 

Votes

Translate

Translate

Report

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 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

Luckily for you, there is a way to collect all the field names in the file without having to write them all out.

Use this code:

 

var rFields = [];
for (var i=0; i<this.numFields; i++) {
	var fname = this.getNthFieldName(i);
	if (fname=="Detective Analyst") continue;
	var f = this.getField(fname);
	if (f==null) continue;
	if (f.type=="button") continue;
	rFields.push(fname);
}

var x = app.alert("STOP! DO NOT clear this form until you saved it under Suspect name; LAST, First & Date. Do you want to clear this form?", 2, 2);
if (x == 4) this.resetForm(rFields);

Votes

Translate

Translate

Report

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 Beginner ,
Sep 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

Try67,

 

Thank you again for all that. I got it working just the way I wanted it. Now I have to figure out the form with 24 fields that cannot be cleared. The one you sent has just "Detective Analyst" - How would I add 23 more names to that script. Just do a couple for me and I'll follow what you did.

 

Thanks,

Lance

Votes

Translate

Translate

Report

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 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

var fieldsToExclude = ["Detective Analyst", "Detective Analyst2", "Detective Analyst3", "Detective Analyst4"]; // enter here the list of field names to exclude from the reset
var rFields = [];
for (var i=0; i<this.numFields; i++) {
	var fname = this.getNthFieldName(i);
	if (fieldsToExclude.indexOf(fname)!=-1) continue;
	var f = this.getField(fname);
	if (f==null) continue;
	if (f.type=="button") continue;
	rFields.push(fname);
}

var x = app.alert("STOP! DO NOT clear this form until you saved it under Suspect name; LAST, First & Date. Do you want to clear this form?", 2, 2);
if (x == 4) this.resetForm(rFields);

Votes

Translate

Translate

Report

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 Beginner ,
Sep 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

try67,

I copies what you gavve me and added 25 field names but every time I paste it in I get a syntax error. Don't know what I am doing wrong. It looks like what you sent me. Could it be the number at the end of each name? Should there be a space between the number and the end of the name? This is what I have:

 

var fieldsToExclude = ["Text2.0","Button3.02"," Button3.13"," Text2.1.1.1.0.04","Text2.1.1.1.15","Check Box36","Text3.0.07","

Text3.1.08"," Text3.1.1.1.19"," Text3.1.1.1.010"," Agency Report Number 11"," Offense#12"," Text7.1.0.1.0.0.013"," Text7.1.0.1.1.0.0.014"," Text7.1.0.1.1.0.0.015"," Text9.0.1.0.1.0.116"," Text7.1.0.1.1.0.0.1.017"," Text9.0.018"," Text9.0.1.0.1.1.1.1.1.1.1.1.1.1.119"," Text9.0.1.0.1.1.1.1.1.1.1.1.0.1.0.1.020"," Text9.0.1.0.1.1.1.1.1.1.1.1.1.1.121"," Text9.0.1.0.1.1.1.1.1.1.1.1.0.1.122"," Text9.0.1.0.1.1.1.1.1.1.1.1.0.1.0.1.1.1.1.1.1.1.1.0.1.1.1.1.1.1.1.1.1.1.1.1.1.023"," Text9.0.1.0.1.1.1.1.1.1.1.1.0.1.0.1.1.1.1.1.1.1.1.0.1.1.1.1.1.1.1.1.1.1.1.1.0.0.1.0.024"," Text5.125","Text826"]; // enter here the list of field names to exclude from the reset var rFields = []; for (var i=0; i<this.numFields; i++) { var fname = this.getNthFieldName(i); if (fieldsToExclude.indexOf(fname)!=-1) continue; var f = this.getField(fname); if (f==null) continue; if (f.type=="button") continue; rFields.push(fname); } var x = app.alert("STOP! DO NOT clear this form until you saved it under Suspect name; LAST, First & Date. Do you want to clear this form?", 2, 2); if (x == 4) this.resetForm(rFields);

 

Votes

Translate

Translate

Report

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 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

What does the error message say? It works fine for me, but maybe you should remove the comment I added before running it.

Also, make sure you spell the field names EXACTLY as they appear in your file. Some of them have a space at the start of the name, which is probably incorrect.

Votes

Translate

Translate

Report

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 Beginner ,
Sep 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

I closed up the spaces as you can see below. After pasting it in I did not get the syntax error but when I click the CLEAR button nothing happens at all. Strange. This is the script I put in:

 

var fieldsToExclude = ["Text2.0","Button3.02","Button3.13","Text2.1.1.1.0.04","Text2.1.1.1.15","Check Box36","Text3.0.07","Text3.1.08","Text3.1.1.1.19","Text3.1.1.1.010","Agency Report Number 11","Offense#12","Text7.1.0.1.0.0.013","Text7.1.0.1.1.0.0.014","Text7.1.0.1.1.0.0.015","Text9.0.1.0.1.0.116","Text7.1.0.1.1.0.0.1.017","Text9.0.018","Text9.0.1.0.1.1.1.1.1.1.1.1.1.1.119","Text9.0.1.0.1.1.1.1.1.1.1.1.0.1.0.1.020","Text9.0.1.0.1.1.1.1.1.1.1.1.1.1.121","Text9.0.1.0.1.1.1.1.1.1.1.1.0.1.122","Text9.0.1.0.1.1.1.1.1.1.1.1.0.1.0.1.1.1.1.1.1.1.1.0.1.1.1.1.1.1.1.1.1.1.1.1.1.023","Text9.0.1.0.1.1.1.1.1.1.1.1.0.1.0.1.1.1.1.1.1.1.1.0.1.1.1.1.1.1.1.1.1.1.1.1.0.0.1.0.024","Text5.125","Text826"]; // enter here the list of field names to exclude from the reset var rFields = []; for (var i=0; i<this.numFields; i++) { var fname = this.getNthFieldName(i); if (fieldsToExclude.indexOf(fname)!=-1) continue; var f = this.getField(fname); if (f==null) continue; if (f.type=="button") continue; rFields.push(fname); } var x = app.alert("STOP! DO NOT clear this form until you saved it under Suspect name; LAST, First & Date. Do you want to clear this form?", 2, 2); if (x == 4) this.resetForm(rFields);

Votes

Translate

Translate

Report

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 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

Check the JS Console for error messages.

Votes

Translate

Translate

Report

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 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

++Adding to the discussion,

 

You're creating too much confusion. This is an unnecessary complication. NesaNurani and Try67 already answered all of this in your past threads. All you need to do is take a little break and sync-in with the overload of information.

 

What you're asking is all documented in page 74 of the Adobe Acrobat SDK JavaScript API
JavaScript™ for Acrobat® API Reference app methods  --->>> see the section for "alert"

 

First off you don't need two buttons to accomplish the tasks that you've been struggling with.

 

Try67 explained to you that you need to define the IF conditions. This can all be done with a single button.

 

Second, the RED X that appears with your alert is normal and that is parameter that can be modified.

 

Note in the image below that I created a button and labeled it "SAVE/RESET". To the adjacent right see all the alert icon and buttons parameters that I've listed for you. You need to keep in mind how to employ these parameters in your script and how the users will interact with the alert messages provided.

 

save_reset.png

 

And see my example script below using the references from Adobe JavaScript API Reference app methods :

 

 

 

// A MouseUp action

var nButton1 = app.alert({

cTitle: "HOW TO SAVE THIS DOCUMENT AND CLEAR THE FORM",

cMsg: "STOP! DO NOT CLEAR THIS FORM UNLESS YOU SAVE IT FIRST. \r\rIf you have not saved this document yet go ahead and click NO to save now, otherwise click YES to clear this form. \r\rWould you like to proceed and clear this form now?", 

nIcon: 4, nType: 2

});


//if user clicks on YES button it will alert the user that it will reset and ask YES or NO to proceed

if ( nButton1 == 4 ) {

// clear and reset all the fields objects in this document
this.resetForm();


} else {


//if user clicks NO button it will alert user with instructions on how to save document

var nButton2 = app.alert({

cTitle: "SAVE THIS FORM",

cMsg: "This document will Save now.\r\rSave this form under Suspect Name: LAST, First & Date",

nIcon: 4, nType: 1

});

if ( nButton2 == 1) {

app.execMenuItem("SaveAs");

  }
}

 

 

Create a new button for testing purposes and Copy this script and paste it in that button as a mouse up event.

 

Observe how the script alerts interact with the choices the user will make and let us know if this is what you asked for.

 

Votes

Translate

Translate

Report

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 Beginner ,
Sep 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

Sorry, I do not know who you are or why you are getting yourself involved in my transaction with NesaNurani and Try67. In any case I made a button as you asked and pasted your code into it and when I click the button nothing happens. Turns out that Nesa got one of my two forms working exactly as I wanted it to work which I am keeping as is. It is my 2nd form that has 25 field names that I do not want cleared when clicking the Clear button. In ending let me say that both NesaNurani and Try67 were told that I am very new at this and have no idea about this code. Many years ago I built a few websites with code because that is all we had and I was dam good at it. Each site had over 150 pages that worked great but that was many years ago when script was the only thing you can use to build sites. Javascript is new to me.

The SAVE/RESET is better then 2 buttons as long as it does not reset fields that I do not want reset. This was never mentioned to me as an alternative. The code you gave me does nothing when I click the button. You can see why I get frustrated. Every code that was given to me did not work until a couple hours ago when Nesa gave me code that worked perfectly in one button for CLEAR FORM. Now I need to do my 2nd form which has 25 field names that cannot be cleared when you click CLEAR. I am at the point of just using reset-a-form and telling everyone to just be careful. At least in that form I can uncheck the fields I do not want cleared.

 

Thanks for your concern,

Lance

Votes

Translate

Translate

Report

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 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

This is a public forum and anyone who wants can contribute to it, especially people with knowledge in this field, like ls_rbls. I suggest you take the advice given to you so far and be a bit more grateful for it.

I, for one, will not provide it to you any longer, considering your attitude.

Votes

Translate

Translate

Report

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 Beginner ,
Sep 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

try67,

 

That is quite okay. Every script you have ever given me has never worked which is why I went elsewhere. I had second thoughts about your knowledge. It is obvious you never checked the script you gave me to see if it worked. I also considered paying adobe for their support knowing I would get the help I needed with them. No need for you to answer any of my inquiries in the future.

Enjoy the day!

Votes

Translate

Translate

Report

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