Script that Triggers if Part of Value is Matched

Contributor ,
Jan 09, 2018

Copy link to clipboard

Copied

I'd like to write a script that matches specific text in part of the field value but not all of it. Is there a way to script that?

The logic would be if the field CONTAINS this specific text, change the text color. If not, keep the text color as black.

Here's what I've tried (tried in both validation and format script with no luck):

if(event.value >= "(T)") {

event.textColor = color.red;

}

else {

event.textColor = color.black;

}

Any suggestions?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

If you want to check whether this string is anywhere within the value, use this:

if (event.value.indexOf("(T)")!=-1) {

TOPICS
Acrobat SDK and JavaScript, Windows

Views

209

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Script that Triggers if Part of Value is Matched

Contributor ,
Jan 09, 2018

Copy link to clipboard

Copied

I'd like to write a script that matches specific text in part of the field value but not all of it. Is there a way to script that?

The logic would be if the field CONTAINS this specific text, change the text color. If not, keep the text color as black.

Here's what I've tried (tried in both validation and format script with no luck):

if(event.value >= "(T)") {

event.textColor = color.red;

}

else {

event.textColor = color.black;

}

Any suggestions?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

If you want to check whether this string is anywhere within the value, use this:

if (event.value.indexOf("(T)")!=-1) {

TOPICS
Acrobat SDK and JavaScript, Windows

Views

210

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 09, 2018 0
Contributor ,
Jan 09, 2018

Copy link to clipboard

Copied

If I change "event" to the defined doc level variable, It simply changes to red regardless. I want it to only change if "(T)" is present in the value.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 09, 2018 0
Most Valuable Participant ,
Jan 09, 2018

Copy link to clipboard

Copied

You're using the wrong operator. ">=" means "larger than or equal to", which doesn't apply to strings.

Replace it with "==".

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 09, 2018 0
Most Valuable Participant ,
Jan 09, 2018

Copy link to clipboard

Copied

If you want to check whether this string is anywhere within the value, use this:

if (event.value.indexOf("(T)")!=-1) {

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 09, 2018 0