Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

to Alphabetize field value

Avatar

Level 5

There are 3 fields named TextField1,TextField2, and TextField3. If user enter "B" in TextField1, "A" in TextField2, and "D" in TextField3, when this file will be closed the value will be rearranged alphabetically. So, "A" in TextField1, "B" in TextField2, "D" TextField3.

Is it possible to do? If so how I can get it?

Also, there is another field named "summarry". All value will be popuated alphabetically.

In addition, the 1st initial of the value will be considered to order alphabetically.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Have a look at John Brinkman's post: http://blogs.adobe.com/formfeed/2009/05/sort_subforms.html.

Here he has a function that you can use to sort subforms/table rows. I've used it here and it works well. You might want to call it on docReady event maybe.

Good luck,

Niall

View solution in original post

11 Replies

Avatar

Correct answer by
Level 10

Hi,

Have a look at John Brinkman's post: http://blogs.adobe.com/formfeed/2009/05/sort_subforms.html.

Here he has a function that you can use to sort subforms/table rows. I've used it here and it works well. You might want to call it on docReady event maybe.

Good luck,

Niall

Avatar

Level 10

Here's a quick solution using an array.

Put this JavaScript into the layoutReady:event of the summary field.

Avatar

Level 5

Hi Nial!

I thought it was not possible. Great!!

In variable scMessage is used. Would you clarify it.

Thanks

Avatar

Level 5

Hi radzmar,

Thanks a lot. Your script accomplishes my project.

I thought it would be a large script but you have done a simple script.

Really great!!!!!

Thanks again.

Avatar

Level 10

Hi,

In John's solution he is calling a function "sort" in a script object "SubformSort".

Within this function, he is calling another function "handleError" in a different script object "scMessage".

So if you are using John's solution, you should include BOTH script objects.

Good luck,

Niall

Avatar

Level 5

Thanks a lot.

I have made a sampe. it works perfectly.

Avatar

Level 5

var aWords = [];

aWords.push(TextField1.rawValue);

aWords.push(TextField2.rawValue);

aWords.push(TextField3.rawValue);

 

aWords.sort();

this.rawValue = aWords.join(",");

If I use add row button to increase the TextField1. In this case if I remove TextField2, TextField3 and use only TextField1, how can I get value into summary field from increased TextField1 (TextField1[0], TextField1[1], TextField1[2]........)

Actually what happen when add row buuton is used that means what the name of increased fields is?

Avatar

Level 10

Hi,

If the TextField1 is in a repeating Row1, then the reference would be more like:

Table1.Row1[0].TextField1, Table1.Row1[1].TextField1, Table1.Row1[2].TextField1, etc...

See an example here: http://assure.ly/kUP02y. Have a look at the table examples.

You would need to loop through the repeating instances and build the string. Using Radzmar's script as an example:

var aWords = []; // create an array variable

var nRows = xfa.resolveNodes("Table1.Row1[*].TextField1"); // resolve all of the repeating instances

// Loop through the rows

for (var i=0; i<nRows; i++) {

     aWords.push(nRows.item(i).rawValue);

}

aWords.sort(); // Sort the array

this.rawValue = aWords.join(",");

You will need to adjust the script for your form.

Niall

Avatar

Level 5

Hi,

It should work but no result in Summary field.

I have attached file. You can see my fault.

https://acrobat.com/#d=MBul5jUxNChzF9SmN1izfQ

Thanks

Avatar

Level 10

My bad!

I have forgotten to use the .length property of the resolveNodes nRows in the for statement. See below:

var aWords = []; // create an array variable

var nRows = xfa.resolveNodes("Table1.Row2[*].Cell1"); // resolve all of the repeating instances

// Loop through the rows

for (var i=0; i<nRows.length; i++) {

          aWords.push(nRows.item(i).rawValue);

}

aWords.sort(); // Sort the array

this.rawValue = aWords.join(", ");

https://acrobat.com/#d=qJSC7nD*bJGU0RJyn9qgvA

Niall