Skip to main content
Known Participant
October 19, 2019
Question

How to sort accented data in form fields

  • October 19, 2019
  • 5 replies
  • 1887 views

I want to sort the data into form fields. The fields are arranged in a simple table with 10 rows and 3 columns with the headings "Number", "Name" and "Reward". I have the fields "pNum.0" ... "pNum.9", "name.0" ... "name.9" and "rew.0" ... "rew.9".
After filling in the fields I want to click on the "sort" button and sort the filled rows alphabetically according to the "Name" column. Names are also accented, eg "Šimon", "Čeněk" ...

This topic has been closed for replies.

5 replies

try67
Community Expert
Community Expert
October 21, 2019

You can edit the "compare" function to replace all accented characters with non-accented ones before comparing the two strings.

I believe that will solve your problem.

For example:

 

 

var names = ["Simon", "Šimon", "Simona", "Šimona", "Albert", "Zazie"];
names.sort(compare)
console.println(names)

function compare(a, b) {
  a = replaceAccentedChars(a);
  b = replaceAccentedChars(b);
  if (a[0] < b[0]) {
	return -1;
  }
  if (a[0] > b[0]) {
	return 1;
  }
  return 0;
} 

function replaceAccentedChars(s) {
	s = s.replace(/Š/g, "S");
	return s;
}

 

The output is:

Albert,Simon,Šimon,Simona,Šimona,Zazie

Without replacing the accented chars the output is:

Albert,Simon,Simona,Zazie,Šimon,Šimona

try67
Community Expert
Community Expert
October 21, 2019

PS. Your compare function is not very good, in my opinion, as it only compares the first letter. That means that if you compare "Simon" with "Simona" it won't actually compare them but just return the first value each time.

I recommend you change it to comparing the full strings.

Known Participant
October 21, 2019

Thank you for the tip, but I have no idea how to do it. Can you help me, please?

ls_rbls
Community Expert
Community Expert
October 21, 2019

Here you go kamil,

 

I  found this link from a very old thread back in 2009 in which a user named John Brinkman

shared sample of his form with the script in it:

https://blogs.adobe.com/formfeed/2009/05/sort_subforms.html

 

Another useful thread here with assumed answer:

https://forums.adobe.com/thread/1908385

 

and here with correct answer:

https://forums.adobe.com/thread/888025#3931407

 

Hope this helps.

Known Participant
October 21, 2019

All these scripts are written for LiveCycle Designer, they are useless if I am not mistaken. 

Legend
October 20, 2019

The linked sorting stuff is great, thanks for posting it, but unfortunately it's for XFA forms. Not Acrobat forms.

JR Boulay
Community Expert
Community Expert
October 20, 2019

In French language we only have accented vowels (no consonants), and alphabetic sorts always happen correctly.

Acrobate du PDF, InDesigner et Photoshopographe
ls_rbls
Community Expert
Community Expert
October 20, 2019

Hi,

 

Here is a good script to sort raw data in your fields alphabetically.

 

Not sure how this may behave with accentuated names or words but see how this work for you:

 

https://forums.adobe.com/thread/928087

JR Boulay
Community Expert
Community Expert
October 20, 2019

This link lands to the forum home page…  (https://community.adobe.com/)

😞

Acrobate du PDF, InDesigner et Photoshopographe