Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Help Clearing Empty Lines


Level 1


I have created a rather complex form for our team members to be able to complete their inspections in the field using a Tablet PC.

In order to make this easier for them I have populated about 50 different drop down menus with the various choices that apply to each scenario.
These choices are then transported from their "list box" down to a comments section on the second page of the form.
This comments section is a long string of this.rawValue = ListBox1.rawValue + "\n" + ListBox2.rawValue + "\n" etc.. etc. on down the line.

The problem I am having is that by inserting all of these "\n".... by the time I get to the last couple of selections they are no longer fitting on the visible portion of the comments section.
This is compounded by the fact that if one of these selections is not made, say the "violation" was not observed at this location, then I get a blank line for that value... obviously this is from my "\n".

I can go back in at the end of the inspection and delete those rows manually, but I am hoping there is a possibility of perhaps creating a button or inserting an additional script onto my textbox that will allow this cleanup to occur? A single button click is much more user friendly and less prone to producing errors than having the inspectors do the cleanup on each document.

I am also very open to any other suggestions that anyone here may have regarding an alternative way to format this text box so that each violation still shows on its own line, but does not generate that blank line when it is not activated. I was considering using an if else statement but am a little unsure as to how to format that without overwriting the rawValue each time a new selection is added.

Thanks in advance for your assistance. I would be happy to upload the form if that becomes necessary.

2 Replies


Level 10

You can use a regular expression to clean up you comments field.

This sample will look for all line breaks (\n) and carriage returns (\r) that occure between 2 and ten times and replaces them with one singe line break.


Level 1

Okay... I will gladly try that.
If my script is in the calculate field under which field would I put this so that it performs the desired action either actively as the form is being manipulated or at the end?

Thank you for your help.