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

Custom Format Script - Bullet Points in Text Field

Community Beginner ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

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

Views

489

Translate

Translate

Report

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

correct answers 1 Correct answer

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 ");

Votes

Translate

Translate
Community Expert ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

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");
}

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

And being on a Mac shouldn't matter.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Does the file I attached work for you?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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";

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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 ");

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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