3 Replies Latest reply on Dec 14, 2016 1:10 AM by try67

    Avoid searching form fields (form field contains search term)

    joregen123

      Hi everybody, hope someone can help with this one:

       

      I have made a search field integrated into the PDF pages and am currently using this bit of script on a button next to the search field:

       

      var textToSearch = this.getField("searchterm").valueAsString;

      if (textToSearch!="") search.query(textToSearch, "ActiveDoc");

       

      This results in the "Full search" in Acrobat coming up listing all found results within the document, which is great, BUT, it also finds the searched term on every page, because the search field is duplicated on all pages. I am thinking maybe one could pass the search term from the field into a (global?) variable and then clear the search field, so it wouldn't be found on all pages, but the search term would still be saved in the variable. Or maybe there is a way to specify that Acrobat should not search form fields?

       

      Any help would be greatly appreciated!

       

      : )erome

        • 1. Re: Avoid searching form fields (form field contains search term)
          try67 MVP & Adobe Community Professional

          It doesn't look like it's possible to tell the search object to ignore form fields (although I think it should have done that when the markup property is set to false, as fields are a type of annotation, but that's not the case).

          So your only other option is to reset the fields before running the query command, it seems.

          • 2. Re: Avoid searching form fields (form field contains search term)
            joregen123 Level 1

            Hi try67, thanks for chipping in! I am afraid I need more help though, since I haven't had any luck with trying to 'save' the content of the field, then clearing the field and then search for the 'saved' search term, so if anyone has any tips or hopefully some concrete script(s) that will do the trick..?

             

            : )erome

            • 3. Re: Avoid searching form fields (form field contains search term)
              try67 MVP & Adobe Community Professional

              The basic structure of the code would be something like this:

              var textToSearch = this.getField("searchterm").valueAsString;
              
              var fieldsToReset = ["Field1", "Field2", "Field3"]; // etc.
              
              var fieldValues = [];
              for (var i=0; i<fieldsToReset.length; i++) {
                  fieldValues.push(this.getField(fieldsToReset[i]).valueAsString);
              }
              this.resetForm(fieldsToReset);
              
              if (textToSearch!="") search.query(textToSearch, "ActiveDoc");
              
              for (var i=0; i<fieldsToReset.length; i++) {
                  this.getField(fieldsToReset[i]).value = fieldValues[i];
              }
              

               

              It's also possible to make this code completely generic, so that you won't need to hard-code the names of the fields to reset in it, but that's somewhat more complicated.