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

Changing Text Box Border Color to transparent once text is entered

Community Beginner ,
Jun 12, 2020 Jun 12, 2020

Hello,

 

I am going nuts here. I have a form which has a BUNCH of text fields in it. All of my other scripts are working except this one. I am aware that there is a mandatory field option in Adobe BUT I cannot seem to find any settings to turn off the red border once the field has had a value entered into it. The border color simply will not change from the default 'red' even when a vlaue has been entered.

 

So I thought a calc script might do the trick:

 

if (this.getField("LastName").value>="")
{
event.target.strokeColor = color.transparent;
}
else
{
if (this.getField("LastName").value="")
{
event.target.strokeColor = color.red;
}
}

 

The goal is seemingly simple here....

 

IF textbox has no entry border = Red

else 

No border as the textbox has a value in it now.

 

Any help is greatly appreciated.

 

 

On a side note I am shocked that this question has not been asked before. While there are similar topics when I click into them they always turn out to be a similar but unrelated topic.

 

 

Many thanks for any assistance!

 

Rich

TOPICS
PDF forms
3.6K
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
Participant ,
Jun 12, 2020 Jun 12, 2020

Use this in your calculation script for each text field in question:

if ( event.target.value == "") {
event.target.borderColor = color.red;
} else {
event.target.borderColor = color.transparent;
}

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
Participant ,
Jun 12, 2020 Jun 12, 2020

Use this in your calculation script for each text field in question:

if ( event.target.value == "") {
event.target.borderColor = color.red;
} else {
event.target.borderColor = color.transparent;
}

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
Participant ,
Jun 12, 2020 Jun 12, 2020

Also, your code has a >= condition and an = condition both checking for no entry. This will not work as it will always drop out of the with a transparent border regardless of there is a value in the field or not.

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 Beginner ,
Jun 12, 2020 Jun 12, 2020

Actually the wierd thing is that my initial code started them off as red and then wouldn't revert them to red once I cleared the value. Thank you for the code you provided. I had tested that (or something similar) but I had always used the get.thisfield....

 

Appreciate the quick response.

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
Participant ,
Jun 12, 2020 Jun 12, 2020

Sure thing! When referencing the field in code in that field I use "event.target", not "this.getField". The beauty of that in your case is it can easily be duplicated across the rest of your fields doing the same thing.

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 ,
Jun 12, 2020 Jun 12, 2020

That is not weird, as you were assigning the empty string value to the field by using the wrong operator, and therefore that condition was always true, so the stroke color was always red.

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
Participant ,
Jun 12, 2020 Jun 12, 2020
LATEST

Same thing I said.

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