Skip to main content
Participant
July 28, 2017
Question

Default field value when blank

  • July 28, 2017
  • 1 reply
  • 386 views

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?

This topic has been closed for replies.

1 reply

Inspiring
July 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);

}

discoboy1Author
Participant
July 28, 2017

It works!, but some fields have calculations and return 0.00 when data is not filled, so the script does not work in that case.

Inspiring
July 28, 2017

I used the script in a form field that calculated the future value. Note that "" or null string is different from a value of 0.