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

Default value for blank field

New Here ,
Jul 28, 2017 Jul 28, 2017

I am creating calibration certificates, my fields are set as numerical values, but I cannot leave a blank field when data is not available. How can I default the blank fields with "--" using javascript?

TOPICS
PDF forms
4.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
LEGEND ,
Jul 28, 2017 Jul 28, 2017

I would set the field's format to "Custom" and write a custom format script that displays the symbols "--" when empty an the formatted number when number when not blank.

// Custom format field set to format on "Custom";

if(event.value == "")

{

event.value = "--";

} else {

event.value = util.printf("%,2 1.2f", event.value);

}

If you want the field to only accept numbers then you will need to write a custom keystroke script.

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 ,
Jul 28, 2017 Jul 28, 2017

You can set the fields' default values to "--", under Properties - Options.

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
New Here ,
Jul 28, 2017 Jul 28, 2017

Doesn't work since the field format is numbers with 2 decimals

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
LEGEND ,
Jul 28, 2017 Jul 28, 2017

I would set the field's format to "Custom" and write a custom format script that displays the symbols "--" when empty an the formatted number when number when not blank.

// Custom format field set to format on "Custom";

if(event.value == "")

{

event.value = "--";

} else {

event.value = util.printf("%,2 1.2f", event.value);

}

If you want the field to only accept numbers then you will need to write a custom keystroke 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
Explorer ,
Jul 28, 2017 Jul 28, 2017

Not sure what you are trying to do, are you calculating also in this field and therefore cant have zero? or do you just want to show the field blank, this way you can keep the formatting by just making the 0 white text and if the value is >0 it will be black

if(event.value && event.value <= 0)

{

    event.target.textColor = color.white;

  }

else

    event.target.textColor = color.black;

}

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
LEGEND ,
Jul 28, 2017 Jul 28, 2017

Zero is not a blank value. It could be a real computed value.

The code I provided works in a numeric field set to 2 decimal places with a calculated value.

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
Explorer ,
Jul 28, 2017 Jul 28, 2017
LATEST

I agree, your code is the correct answer but the description was unclear what he meant by blank field, it depends on what he is doing with the entries to the fields assuming that sometimes the fields may have numerical entries 🙂

Mike

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