Jump to content

Custom Validatidation Script for 0 Values


jimmacmillan

Recommended Posts

In the "Text Field Properties" > "Validate" > "Use custom validate script:" I've been using the following code in AcrobatPro and it works great to show nothing if the value is 0 on a calculated field.

if(event.value ==0) event.value = "";

My customer is using Nitro PDF and this will not work for him. The field shows "$ 0.00" when it should be blank. How should this be coded to show nothing in Nitro Pro if the value is 0?

 

Thanks

Jim

Edited by jimmacmillan
Link to comment
Share on other sites

  • Power User
Steven Zakulec

I was looking into this, but it's made more difficult because I don't really know Javascript. If you do, I'd be thrilled to work with you on this and try to figure out a solution.

Using the code above as a Custom Format Script seems to be the most promising (it will blank out), but then you have to re-format the number since you're not using one of the builtin types. Haven't quite got the hang of the format string to make it a currency type.

Link to comment
Share on other sites

  • Power User
Steven Zakulec

I think I've got it- again, not being a Javascript person, this is likely not the best or cleanest way to do it, but it does seem to work.

Based on the examples from here: https://answers.acrobatusers.com/display-number-value-as-comma-separated-q75347.aspx

this code does seem to work when you put it into a Custom Format Script:

if(event.value ==0) event.value = "";
 else {
var price = event.value;
event.value = util.printf("$%,0 0.2f", price); 
}

 

Link to comment
Share on other sites

On 2/11/2019 at 2:27 PM, Steven Zakulec said:

I think I've got it- again, not being a Javascript person, this is likely not the best or cleanest way to do it, but it does seem to work.

Based on the examples from here: https://answers.acrobatusers.com/display-number-value-as-comma-separated-q75347.aspx

this code does seem to work when you put it into a Custom Format Script:


if(event.value ==0) event.value = "";
 else {
var price = event.value;
event.value = util.printf("$%,0 0.2f", price); 
}

 

For me it's still not working. Even just trying the first line by itself the result should be blank if the event.value is 0 which it is on my form.

I'm learning as I go along so we we're definitely helping each other.

Link to comment
Share on other sites

  • Power User
Steven Zakulec

Did you try this as a custom format script instead of a validation script?

If you try to do this as a validation script, event.value doesn't appear to be valid- which is weird, because there's no reason it shouldn't be.  On the other hand, this works as a custom format script.  If it were a validation script, you wouldn't need any line past the first- since it's not, you need to manage the formatting of the text since your format type is set as Custom, and that's what the last two lines manage.

tfPZEHI.png

  • I agree 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.