You are viewing limited content. For full access, please sign in.

Question

Question

Modern Form Designer - Track Character Count

asked on August 11, 2023

Does anyone know how to show character count feedback in the Modern Form Designer? I think I can work out the javascript, but when I put this "<div id="textarea1k2_feedback"></div>" in the Text Below Field, it doesn't work.

Thanks in advance for any help smiley

0 0

Answer

APPROVED ANSWER SELECTED ANSWER
replied on August 14, 2023
const charCount = LFForm.findFieldsByFieldId(15)[0];
LFForm.onFieldChange(async (e) => {
  const count = LFForm.getFieldValues(charCount);
  const maxLength = charCount.settings.maxLength;
  console.log(count);
  await LFForm.changeFieldSettings(charCount, { subtext: `Character's Remaining: ${maxLength - count.length}` })

}, charCount)

 

2 0

Replies

replied on August 12, 2023 Show version history

You have a few options. If you want to use another field, you can use the LEN function in a single line field formula. e.g., =LEN(Multi_Line)

If you want it in the text below field you will have to use JS like this:
 

const charCount = LFForm.findFieldsByFieldId(15)[0];
LFForm.onFieldChange(async (e) => {
  const count = LFForm.getFieldValues(charCount);
  console.log(count);
  await LFForm.changeFieldSettings(charCount, { subtext: `Character Count: ${count.length}` })

}, charCount)

3 0
replied on August 14, 2023

How do you show it to count down. i.e. You have a limit of 300 characters. As you type how do you make to show how many characters you have left?

1 0
APPROVED ANSWER SELECTED ANSWER
replied on August 14, 2023
const charCount = LFForm.findFieldsByFieldId(15)[0];
LFForm.onFieldChange(async (e) => {
  const count = LFForm.getFieldValues(charCount);
  const maxLength = charCount.settings.maxLength;
  console.log(count);
  await LFForm.changeFieldSettings(charCount, { subtext: `Character's Remaining: ${maxLength - count.length}` })

}, charCount)

 

2 0
replied on August 15, 2023

Thanks Zachary this really helped me out!

1 0
replied on August 11, 2023

I think we would need to see your JavaScript to troubleshoot.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.