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

Placeholder text with a formatted number

Participant ,
Apr 05, 2021 Apr 05, 2021

All of the placeholder text I worked with in form fields has relied on a custom format script, but now I want to have a placholder of 0 for a field I want to be formatted with a currency symbol and commas (but no decimal points). If I use the custom format to achieve the placeholder with an if/else event.value, what code can I add to it to format the text with a dollar sign, commas and no decimals? I suspect it involves util.printf but I'm a little stuck as to how to actually write it.

TOPICS
JavaScript , PDF forms
2.1K
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 ,
Apr 06, 2021 Apr 06, 2021

Again, you don't need to mess around with a custom Format script. It's not needed.

You just need to use the On Focus and On Blur events.

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 ,
Apr 05, 2021 Apr 05, 2021

Do you mean that you want to format the value if it's not "0"?

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
Participant ,
Apr 05, 2021 Apr 05, 2021

I want to have a placholder that reads "$ 0" and then when text is entered, I want it to read as "$ 1,000,000"

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 ,
Apr 05, 2021 Apr 05, 2021

Just set the default value as "0", then, and use the built-in Number format setting... You don't need any scripts.

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
Participant ,
Apr 06, 2021 Apr 06, 2021

I did that at first, but it leaves a 0 in the field when you click in and I'd prefer to have it disappear so the user doesn't have to either delete it or account for it in their entry.

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 ,
Apr 06, 2021 Apr 06, 2021
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
Participant ,
Apr 06, 2021 Apr 06, 2021

I've used this precise resource before, it's helped me many times! However, I can't figure out how the code will support both the disappearing text AND formatting the number in the way that I would like inside of the custom format script.

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 ,
Apr 06, 2021 Apr 06, 2021

The formatting is done by the option you select in the Format tab. You don't need to do it the code.

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
Participant ,
Apr 06, 2021 Apr 06, 2021

But if I use a custom format script in the format tab in order to achieve the placeholder text, I can't also use currency formatting, correct? Or am I massively missing something?

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 ,
Apr 06, 2021 Apr 06, 2021

Again, you don't need to mess around with a custom Format script. It's not needed.

You just need to use the On Focus and On Blur events.

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
Participant ,
Apr 06, 2021 Apr 06, 2021
LATEST

Holy MOLEY, I hadn't noticed that the On Focus/On Blur part controlled anything beyond the color (which I don't need here, so I had been ignoring that bit). Thank you so very much for your patience, that is a much less hectic way to set up the field than using a util.printf to achieve formatting that is already built-in.

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