Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Adding a '%' sign to a numeric field

Avatar

Former Community Member
Is there a way to add a percent symbol to the display format of a numeric field. The display patterns for the formatted output don't seem to include a % sign or, alternatively, a way to add your own text into the formatted value.



If I just make it a text field and format the percentages myself, then I can't use the field in some subsequent formulas.



Thanks

Mordechai
8 Replies

Avatar

Former Community Member
If you goto the Display Pattern property in the Field tab of the Numeric Object, you can put a literal into the display pattern



So for a % symbol you would put



z9.99'%'



This would allow you to enter something like 22.75 and it would display 22.75% when you exit the field.

Avatar

Former Community Member
You're right, it works if I set it in the Display Pattern property. However I'm trying to do it programatically and that doesn't seem to work (the form toggles between displaying values and percentages). When I set format.picture.value to "ZZ9.9'%'" I get all 0.0% values. When I set format.picture.value to "ZZ9.9" I get the correct numbers but without the % sign.



function set2pct( field, value )

{

field.format.picture.value = "ZZ9.9'%'";

field.rawValue = 100.0 * value;

var b = field.border;

b.fill.color.value = "255,255,255";

b.edge.color.value = "196,226,222";

field.access = 'readOnly';

}

Avatar

Former Community Member
Curiouser and curiouser. I used app.alert to dump both field.rawValue and field.formattedValue in the function above and got reasonable values such as 13.20144382 and 13.2%, or 18.53093749 and 18.5%.



So the question is, if field.formattedValue does indeed have the correct string in it, why is it displaying in the form as 0.0%? Not only that, but at display time the field clearly contains the correct rawValue number because I have a subtotal that displays 100.0 (which is what the percentages sum to).



Any suggestions?

-- Mordechai



PS, I checked out Picture Clause Specification V2.0 document. It's amusing that the specification document has better examples than the Designer online help file.

Avatar

Former Community Member
Ah yes, this is the refresh bug. Basically, what happens is that when you set some of the properties via script on an event, they do not get refreshed to the UI properly. Another example of this is setting the tooltip text dynamically via script. What you need to do is force a refresh using the presence property. If you put in the following line after setting the picture format, it should work



field.format.picture.value = "zz9.9'%'";

field.presence = "visible";

field.rawValue = 100.00 * value;



Raw Values should always give you the internal value. Then the patterns are applied to this value.



I Agree about the Picture Clause Specs. Actually all the Appendices of the Specification are pretty useful and should be made part of the Designer Docs.

Avatar

Former Community Member
Hi David et al.<br /><br />I think I am running into a similar problem. I have the following code linked to a button. inpu5, out, and out1 are text fields. Inpu5 is set to support Rich Text and has a default value of 'testhtml123':<br /><br />----------------------<br />out.rawValue = inpu5.value.saveXML();<br /><br />inpu5.value.loadXML( '<?xml version="1.0" encoding="UTF-8"?><value><exData contentType="text/html"><body xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xmlns="http://www.w3.org/1999/xhtml" xfa:APIVersion="2.2.4330.0"><p>testxhtml</p></body></exData></value>', 1, 1 );<br /><br />out1.rawValue = inpu5.value.saveXML();<br /><br />inpu5.presence = "visible"<br />----------------------<br /><br />So out shows the XML before the loadXML command, and 'out1' shows it after. It does indeed show the corresponding change, but the actual text field doesn't seem to update to change. Does anyone know how to refresh this text field so reflect the XML change? the presence field doesn't seem to do the trick...<br /><br />Thanks everyone,<br />- Dave<br /><br />P.S. I just noticed some of the XML doesn't show up right, but I don't know if that's necessary.

Avatar

Former Community Member
You cannot call the loadXML method directly on the value node. You must use the exData instead. Here is a version that works for me when I load it into the exData node:



inpu5.value.loadXML('<body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acroform:2.2.5030.0" xfa:spec="2.1"><p >123</p></body>');

out1.rawValue = inpu5.value.saveXML("pretty");



exData is used to store the rich text formatting, whereas value is a generic node which is defined as either a normal value or a ex value.

I started with a body tag as you only need a rich text formatted value underneath the exData node.

Avatar

Former Community Member
This was exactly what I needed! Thanks so much..

Avatar

Former Community Member
I have tried to add the % validation to the numeric field. It does not seem to be working for me. I have tried using z9.9% in the display pattern and the edit pattern. However, when I check the validation in the PDF Preview, when enter a numeric digit, it does not add the % sign. If I manually add the percent sign, it keeps the %, but I want to be able to add any number and it adds the % after.



Does anyone have any suggestions?