Skip to main content
Known Participant
January 27, 2025
Question

how to fix a JavaScript Warning to disable a date field

  • January 27, 2025
  • 2 replies
  • 2071 views

Hello all, I'm revisiting this error that I can't seem to shake. It's kind of weird that when I turn off the custom formatting in the field I am trying to hide, the function works then I change it back. It works after changing it back. Then somewhere along the way it reverts and give off the error warning: JavaScript Window -

"Invalid date/time: please ensure that the date/time exists. Field [ArrestFile.1.Person.DOA ] should match format yyyy/mm/dd"

It does match this custom date format. I'm scracthing my head at this point. Had this form way too long now. Someone help if possible... much appreciated any help at all.

2 replies

Thom Parker
Community Expert
January 27, 2025

Sounds like badly formatted data is being entered into the field. We really need to look at the form to tell what's going on.

However, you may find this article helpful:

https://www.pdfscripting.com/public/Value-Entered-Does-Not-Match-Format.cfm

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
January 28, 2025

thank you however, unfortunately this form is on a classified side so I am unable to send a copy. I also cannot screenshot. The best thing I could do is type any syntax word from word which is a bit much. Is there any other way to mitigate this? I checked out the link & although I essentially understand, it doesn't apply to my situation. I think it's because it's a date field that I am referencing for whatever reason. But it is the correct date format that its supposed to be. 

Known Participant
January 31, 2025

Yea... your right. Wasn't thinking, I suppose out of desparity.  lol! 

However, my predecessor is not here. Besides I believe I did the whole kitchen (document)

I don't want this to get lost in translation.

All I need is the ResetPartialDOA date field to disappear or rather hide when the ArrestFile.1.Content.EntireRecordYN checkbox is clicked. I got it to work but it added an error code. So I did some research & test & it apparently works fine for text boxes & check boxes which is currently happening. However, I figured that this function just doesn't like the date field. So what I did was put a script in the field that is supposed to be a date field. I used the "Custom Keystroke" Script: 

if (event.change)  {

     event.rc = /^[0-9, \/\(/)]+$/.test(event.change);

}

for the field I am trying to hide when the checkbox is clicked. It works but unfortunately the default text field shows the word Off. 

 

I think its something that is extra in this script for the word "Off" to be shown in the field. 

 

I tried adding this script to fix it: 

if (event.target.value === "off")  {

     this.getfield("ArrestFile.1.Person.DOA") .display = display.hidden;

     this.getfield("ArrestFile.1.Person.DOA") .value = " ";

} else {

      this.getfield{"ArrestFile.1.Person.DOA") .display = display.visible;

}

 

To try & get rid of the word Off.

Am I doing too much or not enough?

 

I appreiciate your help if any!

 

See below of the scripts being ran please:

 

ClearRelated Script:

 

function ClearRelated(obj1,obj2,permVisible)

{

        //console.print1n("obj1.name: "+obj1.value);

        //console.print1n("obj2.name: "+obj2.value);

        obj2.value= ((obj1.value!=="Off")

                              ?(()=>{

                                           obj2.display=((!permVisible)?display.hidden:display.visible);

                                            return "Off";

                                           }) ()

                                : ( ( ) =>{

                                              obj2.display=display.visible;

                                              return obj2.value;

                                             }) () ) ;

}

 

ResetPartialDOA Script:

 

function ResetPartialDOA(obj1,obj2)

{

        console.print1n(obj1.name: "+obj1.value);   

        console.print1n(obj2.name: "+obj2.value); 

        console.print1n(this.getField("RequestType.Seal") .name+ ": " + this.getField("RequestType.Seal").value); 

        

         obj2.display= ((obj1.value==="Off") | | (this.getField("RequestType.Seal").value!=="Off"))

                             ? ( ( ) =>{

                                            obj2.value=" ";

                                            return display.hidden;

                                        } ) ()

                             : ( ( ) => {

                                           obj2.value=obj2.value;

                                           return display.visible;

                                       } ) () ; 

 

SetPubDate Script:

 

function SetPubDate ()

{

        var pubDate=this.info.FromRevision;

        var pubDateFld=event.name==="Format"?event:this.getField("DocPubDate");

 

        if (pubDate&&(pubDateFld.value!==pubDate) )  {

               pubDateFld.value=pubDate;

               console.print1n("Set PubDate: " + pubDateFld.value);

        }

}

 

& last but not least the ToggleAllRelated Script

 

function ToggleAllRelated(numRows)

{

       for(var i=1;i<=numRows;i++) {

              var obj1=this.getField("ArrestFile."+i+".Content.PartialYN");

              var obj2=this.getField("ArrestFile."+i+".Content.PartialDesc");

              //console.print1n(obj2.name);

              ResetPartialDOA(obj1,obj2);

        }

}

 


I new addition will not even run.

 

It even says that there's an error on line 5 in the colon but I don't get it.

PDF Automation Station
Community Expert
January 27, 2025

Please upload the form.