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

Conditional Formatting or number field

Contributor ,
Nov 03, 2022 Nov 03, 2022

Hello there,

 

I'm trying to change the format of text depending on a text field value

I don't know where is the wrong in my code!

it's not working

 

what I want is:

make the text red bold and italic if Actual_lodgning_1 >  lodging_per_diem_1

 

Thanks in advance

 

This is the code:

if(event.value>Number(this.getField("lodging_per_diem_1").value))
{event.target.textColor = color.red;}

else if(event.value < Number(this.getField("lodging_per_diem_1").value))
{
event.target.textColor = color.black
event.target.fillColor = color.transparent;}

Actual_lodgning_1

 

SaherNaji_0-1667467859079.png

 

 

TOPICS
JavaScript , PDF forms
1.5K
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
Community Expert ,
Nov 03, 2022 Nov 03, 2022

It will only work when the value of "Actual_lodgning_1" is changed and not when "lodging_per_diem_1" is changed.

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 ,
Nov 03, 2022 Nov 03, 2022

The code seems fine. Where did you place it, exactly (under what event)?

And are there any errors in the JS Console when it runs?

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 ,
Nov 03, 2022 Nov 03, 2022

To make the text italic you must change the font.

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
Contributor ,
Nov 03, 2022 Nov 03, 2022

 

it's under custome validation script

 

SaherNaji_0-1667477524840.png

 

there is no erros, it's not working!

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 ,
Nov 03, 2022 Nov 03, 2022

It will only work when the value of "Actual_lodgning_1" is changed and not when "lodging_per_diem_1" is changed.

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
Contributor ,
Nov 03, 2022 Nov 03, 2022

Yes, this is what I want to change, but also it's not working

https://watch.screencastify.com/v/eeslnjtWPr8Oe8ZqzzuX

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
Contributor ,
Nov 03, 2022 Nov 03, 2022

Sorry , it's working now, I did a mistake, maybe I did not try to change Actual_lodgning_1

how could I change the font to italic? 

font.HelvB

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
Contributor ,
Nov 03, 2022 Nov 03, 2022

if(event.value>Number(this.getField("lodging_per_diem_1").value))
{event.target.textColor = color.red,
event.target.textFont = font.HelvBI;
}

else if(event.value < Number(this.getField("lodging_per_diem_1").value))
{
event.target.textColor = color.black
event.target.fillColor = color.transparent;}

 

<div>it's working 100%, I did not change the text, but I have to change it, Is there anyway to make it run automatically? when any value changes the color changes</div>

 
 
 
 
it's working 100%, I did not change the text, but I have to change it!
Is there anyway to make it run automatically? So when any value changes the color changes
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 ,
Nov 03, 2022 Nov 03, 2022

Use the script as calculation 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
Contributor ,
Nov 04, 2022 Nov 04, 2022

it's working very will with as calculation script.

thank you very much

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 ,
Nov 03, 2022 Nov 03, 2022

As Bernd said, use script as calculation and just a tip if you first enter value in "Actual_lodgning_1" it will still make text red although "lodging_per_diem_1" is empty because blank value is same as 0, so you might want to check in your script that "lodging_per_diem_1" is not empty or 0 before changing text to red and italic.

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 ,
Nov 03, 2022 Nov 03, 2022

You should also change the conditions to cover the cases where the two values are the same. If you don't, you might end up with some fields in red and others in black, while they are both the same, which is not consistent.

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 ,
Nov 03, 2022 Nov 03, 2022

See the textFont property here:

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html?highlight=textf...


Acrobate du PDF, InDesigner et Photoshopographe
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
Contributor ,
Nov 04, 2022 Nov 04, 2022
LATEST

That's a mazing, thanks bro

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
Contributor ,
Nov 03, 2022 Nov 03, 2022

Thanks for all of you

Gonna try this today

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