Skip to main content
jadef82210029
Participating Frequently
April 13, 2022
Resuelto

Change field colour depending on empty or completed field

  • April 13, 2022
  • 3 respuestas
  • 5035 visualizaciones

Hi - I have an editable PDF form, that I basically want to turn all the fields red if the boxes are empty, once they have been completed they turn back to white - note they are just free text boxes not based on any specific values.

 

Its just as a prompt to the user to complete the field.

 

Can you advise please? I have got close using code I have found online but can't seem to get it to work correctly.

Este tema ha sido cerrado para respuestas.
Mejor respuesta de try67

So I have toggled off the 'Show Border hover color for field' so it changed all fields to white.

 

However, I have added in the validation script to a couple of fields and no colour shows at all.


You have to change their values or clear the form for it to kick in.

3 respuestas

JR Boulay
Community Expert
April 14, 2022

"Thank you - I get a SyntaxError:syntax error 2:at line 3"

Sorry.

 

"do you know how to make it apply to check boxes too?"

The principle is the same but as checkboxes don't have "Validate" nor "Calculation" it is necessary to execute the script from another field.

Acrobate du PDF, InDesigner et Photoshopographe
JR Boulay
Community Expert
April 14, 2022

Place this script as a Validation script in each concerned field:

 

if (event.value == event.target.defaultValue) {event.target.strokeColor = color.red};
else {event.target.strokeColor = color.white};

Acrobate du PDF, InDesigner et Photoshopographe
jadef82210029
Participating Frequently
April 14, 2022

Thank you - I get a SyntaxError:syntax error 2:at line 3, can you advise please?

jadef82210029
Participating Frequently
April 14, 2022

- Add another line where you set the fillColor property, too. Like this:

 

if (event.value == event.target.defaultValue) {
	event.target.strokeColor = color.red;
	event.target.fillColor = color.ltGray;
}
else {
	event.target.strokeColor = color.white;
	event.target.fillColor = color.white;
}

 

- You probably enabled the fields highlighting, which will override these colors. To disable it go to Edit - Preferences - Forms and tick off "Show border hover color for fields". You can also do it from the purple bar at the top of the document when you open it.


So I have toggled off the 'Show Border hover color for field' so it changed all fields to white.

 

However, I have added in the validation script to a couple of fields and no colour shows at all.

Amal.
Community Manager
Community Manager
April 13, 2022

Hi Jadef

 

Hope you are doing well and sorry to for the trouble.

 

Please open the PDF form in Acrobat Pro DC >  Go to Tools > Prepare Form > Double click on the Form field to open the form field properties and Select 'Required' to make the field required.

 

It will force the user to fill in the selected form field. If the user attempts to submit the form while a required field is blank, an error message appears and the empty required form field is highlighted.

https://helpx.adobe.com/acrobat/using/pdf-form-field-properties.html

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Regards

Amal

try67
Community Expert
April 13, 2022

This does not achieve what they asked for. A required field will always be painted in red, regardless of whether it has a value.

jadef82210029
Participating Frequently
April 14, 2022

Hi Try67

 

Yes this is correct, I want all the fields red if the boxes are empty, once they have been completed they turn back to white. Do yoy know if this is possible?