Skip to main content
Inspiring
April 21, 2017
Answered

Alternate Message when Pressing "Clear Form" Button after Form has been Signed

  • April 21, 2017
  • 1 reply
  • 814 views

Hi,

I’m wondering if you can help me with this.  I have been trying to make it happen for about two weeks now.  I’ve tried everything.

The User Signature field has code in the Signed Tab saying that if the form is signed, add today’s date in the DateField.  It also says to lock all of the fields that come before the User Signature Field.

This works:

// Add the date at signing time

    var currentTime = new Date()

    var month = currentTime.getMonth() + 1

    var day = currentTime.getDate()

    var year = currentTime.getFullYear()

    var signingTime = month +"/"+day+"/"+year  //Modify into your preferred format

    var f = this.getField("UserSigDate");  //Modify the field name as necessary

    f.value = signingTime;

//Lock the fields above "UserSig" when signed

this.getField("Name").readonly = true;

this.getField("FaveTVShow").readonly = true;

this.getField("FaveColor").readonly = true;

this.getField("HatSize").readonly = true;

this.getField("checkbox1").readonly = true;

this.getField("checkbox2").readonly = true;

this.getField("checkbox3").readonly = true;

this.getField("checkbox4").readonly = true;

this.getField("Explain").readonly = true;

this.getField("UserSigDate").readonly = true;

After the form has been signed, and saved as a different file, all of the fields above the signature have been locked (made “read only”).  BUT, one problem … If someone presses the “Clear Form” button, all of the locked fields clear out!   : \

What I am trying to do is, put javascript in the “Clear Form” button that says:

If the signature field is already signed, show a message that says “This form has been signed and cannot be cleared.  And have it only show the “OK” button for the response.

If the signature field is empty, show a message that says “Are you sure you want to clear all data from the form?  Yes/No Response buttons.

Currently, I just have the code in the Clear Form button doing the latter, above.  It asks if they are sure they want to clear the form, and the Yes/No buttons work perfectly.

This works:

var cResponse = app.alert({

cMsg: "All data entered will be cleared from this form!\r\rAre you sure you want to clear all the data?",

nIcon: 2, nType: 2,

cTitle: "Clear Form"

});

// clear form if response is "Yes"

if (cResponse == 4) {

this.resetForm();

}

I just don’t know how to add the part about, if the form has been signed, only show the message that it’s been signed and cannot be cleared (with only an OK button for the Response).

I thought I had it working just fine for a while there, until I realized that even when the form WASN’T SIGNED, it still said that the form was signed and would not allow clearing of the data.

Not Working:

//If form has been signed, give msg cannot clear and provide OK response button.

//If form has not been signed, give msg are you sure you want to clear form Yes No

if (this.getField("UserSig") != "") {

var cResponse = app.alert({

cMsg: "This form has been signed and cannot be cleared.",

nIcon: 3, nType: 0,

cTitle: "Clear Form"

})

} else {

if (this.getField("UserSig") == "") {

var cResponse = app.alert({

cMsg: "All data entered will be cleared from this form!\r\rAre you sure you want to clear all the data?",

nIcon: 2, nType: 2,

cTitle: "Clear Form"

});

// clear form if response is "Yes"

if (cResponse == 4) {

this.resetForm();

}

}

}

I have tried so many different ways of doing this, and just need some help at this point.  Is it possible to do this?  When I say “if the form has been signed … “  and “if the form has not been signed … “   there is also the “if response is Yes or No … “ to the "Clear Form" part to deal with.

Here is a link to the form in Dropbox:  Dropbox - Sample Form-Clear_Dont Clear Form3.pdf

Any help would be appreciated.

Thank you.

This topic has been closed for replies.
Correct answer jillie60247986

Thank you so much, Bernd!      It worked.

I actually started to try that last night, and then didn't go through with it.

Again, thank you, thank you.

Have a great day!  : )

1 reply

Bernd Alheit
Community Expert
Community Expert
April 21, 2017

You must check the value of the field, not the field.

Something like this:

if (this.getField("UserSig").value != "") {

jillie60247986AuthorCorrect answer
Inspiring
April 21, 2017

Thank you so much, Bernd!      It worked.

I actually started to try that last night, and then didn't go through with it.

Again, thank you, thank you.

Have a great day!  : )