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

Custom Format Script - Bullet Points in Text Field

Community Beginner ,
Dec 11, 2023 Dec 11, 2023

Hi everyone,

I'm trying to make answers in a multi-line text field format into bullet points. I've used this script posted elsewhere on the forum that works:

if(event.value != "") {
event.value = event.value.split(/\r|\n/).map(function(a){return "\u2022 " + a}).join("\n");
}

However, I was wondering if there's a way for the user to see the bullet points when they type their answer, as they only appear after they click out of the text field.

Best

TOPICS
PDF forms
2.7K
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 ,
Dec 11, 2023 Dec 11, 2023

Use this as 'Custom keystroke script' under 'Format' tab:

if (event.value === "")
 event.change = "\u2022 ";
else
 event.change = event.change.replace(/\n/g, "\n\u2022 ");

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 ,
Dec 11, 2023 Dec 11, 2023

In order to do that you can't use the Format event, as that doesn't actually change the field's value.

You need to move your code to the Validation event, for example. But then there's a new issue: You will need to change it so that it doesn't add the bullet-points if they already exist at the start of a line, or you'll end up with a new bullet each time you edit the field.

One way to do that is the following:

 

if(event.value != "") {
	event.value = event.value.split(/\r|\n/).map(function(a){return "\u2022 " + a.replace("\u2022 ", "")}).join("\n");
}
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 ,
Dec 11, 2023 Dec 11, 2023

Hi try67,

Thanks for responding and your help 🙂

I've tried adding that as a custom script in the Validation section, but it isn't doing anything. Do I need to use it in conjunction with anything else? I'm using a Mac if that helps.
Best

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 ,
Dec 11, 2023 Dec 11, 2023

No, nothing else is needed. Did you remove the Format script?

And being on a Mac shouldn't matter.

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 ,
Dec 11, 2023 Dec 11, 2023

I've removed all other scripts. Should I add it back in? Thanks again

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 ,
Dec 11, 2023 Dec 11, 2023

No. Be aware this will only work when you exit the field, though, not while you're typing into it.

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 ,
Dec 11, 2023 Dec 11, 2023

Is there a way to make it appear when you're typing into it? or would it be best to paste the unicode in as the default answer to start?

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 ,
Dec 11, 2023 Dec 11, 2023

To avoid empty lines from having a bullet added to them, use this:

 

if (event.value != "") {
	event.value = event.value.split(/\r|\n/).map(function(a){if (a!="") return "\u2022 " + a.replace("\u2022 ", "")}).join("\n");
}

 

Attached is a working example.

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 ,
Dec 11, 2023 Dec 11, 2023

Sadly, neither code is working for me... I'm not sure why

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 ,
Dec 11, 2023 Dec 11, 2023

Does the file I attached work for 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 Beginner ,
Dec 11, 2023 Dec 11, 2023

Yes, that form works. I think I've made it work based on another script you wrote on another post:

I set the keystroke script to:
if (event.change=="\n") event.change+="\u2022\t";

and I created an On Focus trigger:
if (event.target.value=="") event.target.value="\u2022\t";

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 ,
Dec 11, 2023 Dec 11, 2023

Use this as 'Custom keystroke script' under 'Format' tab:

if (event.value === "")
 event.change = "\u2022 ";
else
 event.change = event.change.replace(/\n/g, "\n\u2022 ");
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 ,
Dec 11, 2023 Dec 11, 2023
LATEST

I'll try this too. Thanks so much Nesa!

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