Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


javascript help

Explorer ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

1. Lets say checkbox export value is set to 5, Is it possible to get that value in calculation  even if checkbox is not checked?

 

2. How to properly get array from this code, now I get all values out at once:

var x = ["$20","$40","$3","$10","$9"];
for (var i=1; i<=5; i++) {
var spans = new Array();
spans[0] = new Object();
spans[0].text = x+i;}

 

TOPICS
JavaScript

Views

200

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
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Feb 05, 2021 Feb 05, 2021
If I understand you correctly, this code should do the trick: var x = ["$20","$40","$3","$10","$9"]; for (var i=1; i<=5; i++) { var f = this.getField("t"+i); var spans = new Array(); if (this.getField("text"+i).valueAsString!="") { spans[0] = new Object(); spans[0].text = x[i-1]; } f.richValue = spans; }

Likes

Translate

Translate
Adobe Community Professional ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

1. Yes, you can do it by checking the exportValues property of the field, which returns an array of all the export values of the fields in the group. If there's only one field the array will have one item.

2. Your question is not clear. Do you mean that you want to convert that array of strings to an array of Span objects?

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
community guidelines
Explorer ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

Sorry about that, Il try to explain,I have 5 text fields named "text1','text2...etc' and 5 text fields names 't1,'t2...etc' where I use spans code. if text1 is not empty i want it t1 to populate with first item in array,if text3 is not empty I want it to populate with 3rd item in array..,etc. I didn't want long code so I'm trying to do it with for var i if possible

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
community guidelines
Adobe Community Professional ,
Feb 05, 2021 Feb 05, 2021

Copy link to clipboard

Copied

If I understand you correctly, this code should do the trick:

 

var x = ["$20","$40","$3","$10","$9"];
for (var i=1; i<=5; i++) {
	var f = this.getField("t"+i);
	var spans = new Array();
	if (this.getField("text"+i).valueAsString!="") {
		spans[0] = new Object();
		spans[0].text = x[i-1];
	}
	f.richValue = spans;
}

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
community guidelines
Explorer ,
Feb 05, 2021 Feb 05, 2021

Copy link to clipboard

Copied

Yes I belive it's on right track but unfortunately I'm not getting anything and when run code in debugger I get this:

InvalidSetError: Set not possible, invalid or unknown.
Field.richValue:10:Console undefined:Exec

undefined

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
community guidelines
Adobe Community Professional ,
Feb 05, 2021 Feb 05, 2021

Copy link to clipboard

Copied

Did you set the fields as having rich text formatting?

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
community guidelines
Explorer ,
Feb 05, 2021 Feb 05, 2021

Copy link to clipboard

Copied

Silly me, I was making new file and forgot to set it.

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
community guidelines
Adobe Community Professional ,
Feb 05, 2021 Feb 05, 2021

Copy link to clipboard

Copied

Why does you use one spans object?

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
community guidelines
Explorer ,
Feb 05, 2021 Feb 05, 2021

Copy link to clipboard

Copied

I use some other stuff for rich text formatting, thats why i need code to work with spans object.

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
community guidelines
Explorer ,
Feb 05, 2021 Feb 05, 2021

Copy link to clipboard

Copied

Just one more thing, I'm trying to replace array with checkbox export value array.

In the post above you write if it's group it will get all items, unfortunatelly my fields are named C1,C2...etc so it's not a group, but is there an easier way to get them then like this this?

var x1 = this.getField("C1").exportValues;
var x2 = this.getField("C2").exportValues;
var x3 = this.getField("C3").exportValues;
var x4 = this.getField("C4").exportValues;
var x5 = this.getField("C5").exportValues;
var x = [x1[0], x2[0], x3[0], x4[0], x5[0]];

 

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
community guidelines
Adobe Community Professional ,
Feb 05, 2021 Feb 05, 2021

Copy link to clipboard

Copied

This seems fine to me... Is it not working well?

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
community guidelines
Explorer ,
Feb 05, 2021 Feb 05, 2021

Copy link to clipboard

Copied

It is working, I was just wondering is there another way to do it.

But nvm all is good and thank you for all your help.

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
community guidelines
Adobe Community Professional ,
Feb 05, 2021 Feb 05, 2021

Copy link to clipboard

Copied

LATEST

You can also do it like this:

 

var x = [];
for (var i=1; i<=5; i++) x.push(this.getField("C"+i).exportValues[0]);

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
community guidelines