Copy link to clipboard
Copied
I have tried a few options without success.
I have a startDate text field with light grey format info to inform the user (MM-DD-YYY).
When data is entered I want the date format to be replaced by the user's data.
So far I have tried...
Option 1 - MM-DD-YYYY is the field default value. Unfortunately when I enter data in the field it does not replace the default value but rather just adds to it. Is there a way to select all data on field entry so that typing would replace what is selected by the date the user enters ?
Option 2 - MM-DD-YYYY is text that is under the field. The form fiels background color is transparent. I tried changing that thru javascript to white when there is data in the field - I was hoping that the white would cover the text that is underneath. Does not work - I wonder if it is because by default the form is set to highlight the form fields in white instean of the typical lighr blue.
Option 3 - MM-DD-YYYY is in a field that is locked and read only. I was hoping to change the field visibility based on the value of the date field. So if date is empty the MM-DD-YYYY field is visible, else it's hidden. The issue I have is that my start date field seems to be stuck under my disply field for the MM-DD.... I can't seem to send it to the back layer, so I can't enter data in the date field. This option worked when I was testing and the fileds were next to each other instead of on top of one another.
What would be the best practice to have this functionality ? My coding experience is very limited but I am willing to read up and follow suggestions.
Thanks,
D
Copy link to clipboard
Copied
If you didn't set format as date, then use script as custom format script.
Copy link to clipboard
Copied
There are a couple of things you could do.
If you have field format set as date, then you can use field 'Validate' script:
if(!event.value)
event.value = "MM-DD-YYYY";
Although it will work almost same as default value, when entering date select all text.
Copy link to clipboard
Copied
Thanks Nesa.
I forgot to mention that the startDate field is actually a text field.
I want user to be able to write things like +/- 08-08-2023 if a specific date is not known when they fill the form.
Copy link to clipboard
Copied
If you didn't set format as date, then use script as custom format script.
Copy link to clipboard
Copied
Oh my god ! That is so simple, it's awesome - works perfectly.
Can I push my luck and ask... is there a way within the custom format script to make the "MM-DD-YYYY" light gray, BUT when data is entered it reverts back to black ?
Copy link to clipboard
Copied
Try this:
if(!event.value){
event.target.textColor = ["G", 0.7];
event.value = "MM-DD-YYYY";}
else
event.target.textColor = color.black;
Copy link to clipboard
Copied
Thanks Nesa. I will just leave everything black.
It's not working and it seems to affect the "MM-DD-YYYY" data - I end up typing inside the MM-DD-YYYY instead of replacing it. I tried moving the code to the validate tab. Also to split it so the formating stays in the custom format script and the color change goes in the validate tab - did not work. I also tried to change the color in the action tab - on mouseUp and on Blur trigger, so that based on the content of the sratDate field the color would either be black or gray. Can't seemt o get that to work either.
Copy link to clipboard
Copied
Here is a sample file with two different solutions:
https://drive.google.com/file/d/1U-GvqFVw-7I9sxlSzm4MHYaEnH2x4fJD/view?usp=sharing
Copy link to clipboard
Copied
Thank you so much.
Interesting that your examples work but behave differently when copied and pasted on my form.
I will dig into it some more. Thank you again for the code snipets - helps me to see that I was not way off. I just have to find why the behavior is different at my end.
Copy link to clipboard
Copied
Nesa, Thanks again for your help. For a reason I don't understand I had to change a bit of your code to work on my form.
I ended using the custom format code :
if(!event.value){
event.target.textColor = ["G", 0.7];
event.value = "MM-DD-YYYY";
}else{
event.target.textColor = ["G", 0];
}
I am a little confused because I saw this acrobat color tutorial page (belwo).
Based on the info ["G", 0] should be white but on my form it gives me the black text.
Copy link to clipboard
Copied
It's an error on that website, 0 is black, 1 is white.

