9 Replies Latest reply on Feb 11, 2014 4:59 PM by berocca

    Date field that you can also put N/A into

    berocca Level 1

      Hi chaps,

       

      I have a bit of a dilemma. I have a bunch of text boxes that are used as date fields ie. set as "dd-mm-yyyy" format. However, they ALSO need to allow "N/A" to be typed/ or pre-filled into them but nothing else.

       

      I'm assuming that the date format needs to be set as javascript rather than in the properties, but is anyone able to point me in the direction of the code I need to use?

       

      Thanks.

        • 1. Re: Date field that you can also put N/A into
          George_Johnson MVP & Adobe Community Professional

          It would be easier if you could just add a check box to indicate N/A. Is that possible?

          • 2. Re: Date field that you can also put N/A into
            berocca Level 1

            Hi George,

             

            I'm not exactly sure what you mean by a "Checkbox to indicate N/A" but if it means that the "N/A" will NOT appear in the text boxes, then no, not really.

             

            They are currently used as normal text boxes with no formatting. The user types the date in or types in N/A, whichever is appropriate to the situation. We would like to force the date to always be in dd/mm/yyyy format, but it seems that doing so stops them from also typing in N/A when they need to. Also, in the future I would like to set up a sitation where the N/As are pre-filled depending on what the user does earlier in the form, just have to get it to allow Letters first thogh.

             

            If it is not possible, I will need to chose one function over another or keep typing everything in manually

            • 3. Re: Date field that you can also put N/A into
              George_Johnson MVP & Adobe Community Professional

              OK, this isn't too difficult. I'll be able to post something later...

              • 4. Re: Date field that you can also put N/A into
                berocca Level 1

                No worries at all George. Thank you very much in advance, I really appreciate your help.

                 

                Unfortunately, I can see this "N/A" thing coming up a lot in our company. In many of our forms, there MUST  be something in EVERY field. Where we don't have data (For example: An email address field but the person doesn't have email) we still have to put something there, so we put N/A. I'm finding this is hampering a lot of my attempts to use Javascript to make things more streamlined.

                 

                (Again with the email address example: I could have a validation script to minimise mistakes when entering email addresses, but if I do that, then it wont let me enter N/A when I need to! Grrrrrrr ).

                 

                I'm hoping that there is a way around this!

                • 5. Re: Date field that you can also put N/A into
                  George_Johnson MVP & Adobe Community Professional

                  There's always a way, and fortunately you can take advantage of the built-in routines for the normal cases and bypass them for the N/A case. First read through the following previous topic (starting at #13) where I talk about using some document-level scripts: http://forums.adobe.com/thread/1040667

                   

                   

                  For this case, you could use the following two scripts that get called in the format and keystroke events of the date fields:

                   

                  function date_format1() {

                   

                      if (event.value.toUpperCase() !== "N/A") {

                          AFDate_FormatEx("dd-mm-yyyy");

                      }

                     

                  }

                   

                  function date_keystroke1() {

                   

                      if (event.willCommit && event.value.toUpperCase() === "N/A") {

                          // Do nothing

                      } else {

                          AFDate_KeystrokeEx("dd-mm-yyyy");

                      }

                     

                  }

                   

                  So this would accept "n/a", "N/A", "N/a", and "n/A" as valid entries that indicate not applicable, and otherwise allow normal date entry.

                   

                  You can do the same type of thing for validating email addresses. There is a built-in email address validation routine that's pretty good and is discussed here: http://forums.adobe.com/thread/857974

                  1 person found this helpful
                  • 6. Re: Date field that you can also put N/A into
                    berocca Level 1

                    Thanks George! It took a bit of fiddling around as I wasn't familar with document level scripts but I got there in the end!

                     

                    Your suggestion works great!

                    • 7. Re: Date field that you can also put N/A into
                      berocca Level 1

                      Hi George, just wondering if it is possible to change the automatic message that appears when an invalid entry is made? I have seen the app.alert function around, however, I don't understand how to use it in this situation.

                       

                      Ideally I would like the message to be something a little more clear, e.g. "Date field may only contain either a date in dd/mm/yyyy format, OR 'N/A'."  Is this possible?

                      • 8. Re: Date field that you can also put N/A into
                        George_Johnson MVP & Adobe Community Professional

                        Sure, just delete the date_keystroke1 function that you currently have and add these two to the document-level JavaScript:

                         

                        function date_keystroke1() {

                            if (event.willCommit && event.value.toUpperCase() === "N/A") {

                                // Do nothing

                            } else {

                                AFDate_KeystrokeEx2("dd-mm-yyyy");

                            }

                        }

                         

                        function AFDate_KeystrokeEx2(cFormat) {

                            if (event.willCommit && !AFParseDateEx(AFMergeChange(event), cFormat)) {

                                if (event.willCommit && !event.silenceErrors) {

                                    app.alert("Date field may only contain either a date in dd-mm-yyyy format, OR \'N/A\'.", 1);

                                } else {

                                    app.beep(0);

                                }

                                event.rc = false;

                            }

                        }

                         

                         

                        The last function is just a customized version of the built-in one (AFDate_KeystrokeEx), but renamed so it doesn't clash.

                        • 9. Re: Date field that you can also put N/A into
                          berocca Level 1

                          Awesome! Thank you!