Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Sort form field data alphabetically

New Here ,
Jan 22, 2019 Jan 22, 2019

Hi, is it possible to sort a list of names alphabetically in a form field. I don't want to use the list function, as the names change daily and I don't want to have to edit the form for my staff every time a new name appears. Is there a script that would automatically sort the names alphabetically in the form field.

Thanks

TOPICS
PDF forms
5.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Jan 28, 2019 Jan 28, 2019

You can use this code as the field's custom validation script:

if (event.value!="") {

    var names = event.value.split("\r");

    names = names.sort(function(a,b) {if (a<b) return -1; if (a>b) return 1; return 0});

    event.value = names.join("\r");

}

And setting up a calculated value is not difficult at all... If you provide more details I could help with that as well.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2019 Jan 22, 2019

You need to better explain your set-up, but yes, it is possible.

Does this field have a calculated value, or a user-entered one? How are the names separated from each other?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 28, 2019 Jan 28, 2019

Thanks for replying.

I have a multi-line form box that has names in a list format, one underneath another, which are separated by a return. e.g.

Adan Smith

Eve Jones

Jane Doe

Etc.

The field has no calculated value, as I couldn't get my head round how it would work.

I'd like the form field to automatically sort the names alphabetically by their first names, is this possible using a script?

The form was previously in MS Word, but the staff keep wrecking the layout, so was hoping that a PDF form would stop this happening.

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 28, 2019 Jan 28, 2019

You can use this code as the field's custom validation script:

if (event.value!="") {

    var names = event.value.split("\r");

    names = names.sort(function(a,b) {if (a<b) return -1; if (a>b) return 1; return 0});

    event.value = names.join("\r");

}

And setting up a calculated value is not difficult at all... If you provide more details I could help with that as well.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 28, 2019 Jan 28, 2019

Thank you so much, that works perfectly, amazing.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 25, 2020 Jan 25, 2020

Hello,

 

I batch scan hundreds of invoices into a scan folder. I need/want to use Adobe Acrobat DC to sort those hundreds of  invoices alphabetically, is that possible?  Please advise what steps I need to follow in Adobe in order to sort the batch scanned invoices alphabetically.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2020 Jan 26, 2020

This is a new question. Please ask it on a new thread.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2022 Feb 02, 2022

Hi, I have tried to type the advised code into the java script but its not working. 

I am trying to do the same thing...

a list of names first name and last name underneath one another and I would like to sort them alphabetically using a java script.

I went into mouse up function, enter java script and copied this 

if(event.value!=“”){ 

var names = event.value.split(“\r”);

names = names.sort(function(a,b){if(a<b)return -1; if(a>b)return 1; return0});

event.value=names.join(“\r”);

}

but it tells me that there is a syntax error in the second line "var names....".

Any advise would be majorly appreciated. I am a complete newbie with javascript so would be grateful for some advise.

Thank you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2022 Feb 02, 2022

Use " not ” for text strings.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2022 Feb 02, 2022

I am really sorry...what do you mean by that? What do I need to change within my code? Or do I need to put it somewhere else? I put it into Form Field "Action", "Mouse up", "Java Script"

Is that wrong for this code? Still trying to get my head around the whole Java script 🙈

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2022 Feb 02, 2022

Replace ” with " in your script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2022 Feb 02, 2022

Perfect. Thank you soooo much. It accepted the code now. Just sorting the names isn't working 🙈.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2022 Feb 02, 2022

Don't use Word for code! Only a plain-text editor, like Notepad++.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2022 Feb 02, 2022

I am using acrobat DC and a form field. Is that wrong? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2022 Feb 02, 2022

The issue is with the code. As Bernd pointed out, you've used an incorrect character, namely the curly quotes. You can only use straight quotes in your code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2022 Feb 02, 2022

I see. What a silly mistake. Thank you for pointing this out. It is taking the code now but unfortunately it is not sorting my name list alphabetically. 🙈

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2022 Feb 02, 2022
LATEST

Fixed it. I needed to put it under Calculations - Java Script not Actions. Thank you so much for your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines