Skip to main content
Participant
November 22, 2024
Question

all the placeholder texts to disappear if the form is edited in any way to be saved

  • November 22, 2024
  • 1 reply
  • 1267 views

Hi all, 

 

I am developing a form, and I used JavaScript to add placeholder text. 

I made it so the placeholder txt doesn’t print.

My concern now is that people will just save the placeholder txt (even tho grey-ed out) as their own when they are filling it out digitally for digital signature. 

 

The grey text only disappears when the text field is clicked on. 

How can I make it so all placeholder texts disappear if the form is being saved even tho not all text fields have been edited? 

I can't attach the form because it will be an official form, but I used the below placeholder text: 

 

var message = "My text."

if (event.value == '') {

event.target.display = display.noPrint

event.value = message

} else {

event.terge.display = display.visible

}

 

 

I also used javascript in Actions to change colour 

 

if (event.target.value==event.target.defaultValue) {
event.target.value = "";
event.target.textColor = color.black;
}

 

 

 

What do I need to add to make all the placeholder texts disappear if the form is edited in any way to be saved?


Thank you 

This topic has been closed for replies.

1 reply

S_S
Community Manager
Community Manager
November 22, 2024

Hi @nadina_9931,

 

Hope you are doing well. Thanks for writing in!

 

I tried the below code to achieve your workflow, and it worked:

 

// Placeholder text for all fields
var message = "My text."; // This is your placeholder text

// Function to clear placeholder text when saving the form
function clearPlaceholders() {
    var fields = this.getField("yourFieldName"); // Repeat this for all fields, or loop through all fields
    for (var i = 0; i < fields.length; i++) {
        var field = fields[i];
        if (field.value === message) {
            field.value = ""; // Clear placeholder if it is still there
        }
    }
}

// Trigger when saving the document
this.addEventListener("WillSave", function() {
    // Loop through all fields and remove the placeholder text if it's not filled
    var allFields = this.getFieldNames(); // Get all field names in the document
    for (var i = 0; i < allFields.length; i++) {
        var field = this.getField(allFields[i]);
        // Check if the field has the placeholder message and remove it
        if (field.value === message) {
            field.value = ""; // Clear placeholder text
        }
    }
});

 

Let me know if this helps.


-Souvik

try67
Community Expert
Community Expert
November 22, 2024

It's a shame you're posting invalid code. There's no addEventListener method in Acrobat.

S_S
Community Manager
Community Manager
November 25, 2024

@try67, Thanks for pointing it out. 

 

The event type WillSave is a valid document-level code. 

Also, Acrobat allows triggers based on events like form field interactions.

 

Let me know if the code throws an error, and I'll change it accordingly.

 

-Souvik