Expand my Community achievements bar.

Calculation with text field/numeric field not working when I add $

Avatar

Level 2

Hi,

Client needs the flexibility to add a dollar sign or take it off when filling out a purchase order (they have clients who use Euros, not dollars, and it confuses them). And they want the numbers after the decimal to stay if they are zeros. (Example: 10.00) So I thought I could change the field to a text field. Solved part of the problem. Now the client can type in 10.00 and the zeros stay after the decimal. But if I try to type $10.00, the formula doesn't work and the amount doesn't total. I am adding Ordered*UnitPrice=Amount.

Ideas? Thanks.

7 Replies

Avatar

Level 10

Hi,

You will need to remove the "$" sign and turn the text field value into a number, so in JavaScript something like;

parseFloat(UnitPrice.rawValue.replace("$",""))

 

You will probably need to check that the UnitPrice is not empty first.

Regards

Bruce

Avatar

Level 2

Now I keep getting an error message that the Target version does not support the validation state. Think I'm going with a low tech solution of adding a separate column next to Unit price where the client can add a $ when they need to, or leave it empty when they don't. Can't get rid of the error message, even when I took the script out.

Avatar

Level 10

Hi,  I don't think this message is because of the code we added.  This message is saying that you targeting a version of Reader (see the File ... Form Properties ... Defaults screen but using some functionality that is not available in that version.  The code I have suggested is standard JavaScript available in all version of Reader.

Happy to have a closer look if you can host your form somewhere like www.Acrobat,com and post a link in this thread.

Bruce

Avatar

Level 2

I'm still new at this program, but I know the error message showed up only for the UnitPrice column (The yellow triangle is on each corner of each Unit Price numeric field) and only after I put in the code. I haven't changed any other settings for the form. I'm getting this message in LiveCycle.

Here's the form if you have some suggestions:

https://acrobat.com/#d=G9dyi8Pnao0dblbOYdd5Eg

And am I correct to assume that I can't get the zeros after the decimal to stay unless the field is a text field? They automatically drop off at "enter" if it's a numeric field.

Form hasn't been polished yet, still working on that. Just stymied by the $ issue.

Thanks, Bruce!

Avatar

Level 10

Hi,  To get the currency sign and decimal places to display you can make your field a Numeric Field and then in the Field tab of the Object palette click the patterns button and set the display pattern.  There's a lot to choose from and you can customise them, but "num.currency" would be a good one to try first.

I can't see the form in the link, I think there is a share or publish option to give me access.

Regards

Bruce

Avatar

Level 2

https://acrobat.com/#d=9MCxHAt23C5DW2LM*cDGxw

This is the link I got when I published it on Acrobat. Hopefully this one works for you. I added an invisible column next to Unit Price where the client can add the $ if they want. If you have a better solution, I'll take it.

Thanks!

Avatar

Level 10

Somehow some of your fields have an empty instance of all the events possible, I have never seen a form get into this state, but one of the events is validateState which is only supported in the Reader 9.1 and above.  I have removed all the empty events, but to make this easier for me to do, I removed all but the first row in the table and set that one to repeat 15 times.  It looks different in design view but looks the same when opened in Reader.  Makes calculating the total easier as well.

This is a version using numeric fields with a currency picture format (I like this one because it stops them typing non-numeric values)

https://acrobat.com/#d=y0AaThTM-dWpvKuvmWFdnw

But that will not allow your users to type the currency symbol, so this one uses a text fields but parse the value into a number so it can work out the Amount column, in FormCalc this looks like ordered * Parse("$z,zzz,zzz.zz|z,zzz,zzz.zz", unitprice)

https://acrobat.com/#d=k*l7zMiOPIKBMlx93f2WoQ

This one will also blank out any invalid unit price values entered.

Regards

Bruce