9 Replies Latest reply on May 22, 2014 2:22 PM by Markh1234

    Custom text in drop down boxes?

    Markh1234

      Hi All,

       

      Is it possible to set a text limit when the custom text box is used in a dropdown box? Currently I have drop down options but I'd like the users to put in there own text if required. There is an option for custom text but this gets lost out the box if you type too much. I would like to restrict the custom drop down text if possible? Lets say restrict to 40 letters?

       

      Many Thanks.

        • 1. Re: Custom text in drop down boxes?
          George_Johnson MVP & Adobe Community Professional

          It's possible with a custom Keystroke script. Here's a sample one that's intended to be placed in a document-level JavaScript that you then call with a custom Keystroke script in the dropdown:

           

          function limit_dropdown_chars(max_chars) {

           

              // Get all of the character that are trying to be entered

              var sAll = AFMergeChange(event);

             

              // Don't allow more than the maximum

              if (sAll.length > max_chars) {

                  event.rc = false;

                  app.alert(max_chars + " characters is the limit.", 3);

              }

             

          }

           

           

          THis is how you'd call it in the custom Keystroke script:

           

          limit_dropdown_chars(40);

           

           

          This script could be improved (you may want to remove the alert), but it should get you started.

          • 2. Re: Custom text in drop down boxes?
            Markh1234 Level 1

            Hi George,

             

            I was wondering if you could help me further? I'm currently using this script below to copy

            the text from a drop down box, this then copies to a text box. The script works ok except when I add extra text I cannot save it. When I click off the text box the text automatically chages back to the drop down box text.

            If possible I would like to be able to select the drop down which then populates a text box. After I do this action I would like to add text to the text box and then be able to click of the box and my written text still remains ( still with me). Would you be able to show me how I adapt my script below to do this?

             

             

             

            event.value = "Hazard text box";

             

            var oField = this.getField("Entrance barrier 1");

             

            event.value = oField.value;

             

            Regards

             

            Mark

            • 3. Re: Custom text in drop down boxes?
              George_Johnson MVP & Adobe Community Professional

              Assuming this is a custom calculation script for the text field, you could change the script to:

               

              // Custom calculation script for a text field

              (function () {

               

                  // Get a reference to the dropdown field

                  var f = getField("Entrance barrier 1");

               

                  // Set this field's value to the dropdown value if it was changed

                  if (event.source && event.source === f) {

                      event.value = f.valueAsString;

                  }

               

              })();

               

               

              It's not clear to me what the first line of code is supposed to do in your original script.

              • 4. Re: Custom text in drop down boxes?
                Markh1234 Level 1

                Hi George,

                 

                That works great.

                 

                Thanks for your help

                 

                Mark

                • 5. Re: Custom text in drop down boxes?
                  Markh1234 Level 1

                  Hi George,

                   

                  The script was perfect, except it won't work on my mobile device(I Forgot to mention that bit). I know it's a bit hit and miss with mobile devices but the original script I had did work on my mobile device. Can your script which you kindly wrote for me be adjusted slightly or written so I can use it in a different script area? Your help would be much appreciated.

                   

                  Regards

                   

                  Mark

                  • 6. Re: Custom text in drop down boxes?
                    George_Johnson MVP & Adobe Community Professional

                    It depends on what mobile device you're using and what PDF viewer.  Some don't support JavaScript at all and some have very limited support, while others have pretty good support.

                    • 7. Re: Custom text in drop down boxes?
                      Markh1234 Level 1

                      Hi George,

                       

                       

                      i've been using the mobile version of adobe on a Samsung Galaxy s3. The original script appears to work using this mobile version so I assumed it would be ok, as i'm using adobe products? Is there another reader I can try? I've also notice it only appears to work when I'm using Acrobat on my PC and not in my normal Adobe viewer on my PC? yet my other script did?

                       

                       

                      regards

                       

                       

                      Mark

                      • 8. Re: Custom text in drop down boxes?
                        George_Johnson MVP & Adobe Community Professional

                        Simple calculation scripts like the your original one could work on Adobe Reader for Android, but I hear they had to (temporarily) remove JavaScript support for security reasons. Another PDF viewer that has much more support for JavaScript on Android is qPDF Notes, so it might be worth a try. I don't know if it supports the event.source property, but if it doesn't, the script can be revised so it's a custom Validate script of the dropdown, something like:

                         

                        // Custom Validate script for a dropdown

                        getField("Text1").value = event.value;

                         

                        Where "Text1" is the name of the text field. This assumes the dropdown items don't have export values set.

                        • 9. Re: Custom text in drop down boxes?
                          Markh1234 Level 1

                          Hi George,

                           

                          Your a top man!. That last script worked on all formats.

                           

                          Thanks very much.

                           

                          Mark