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

[JS][CS5] doScript problem

Participant ,
Mar 03, 2011 Mar 03, 2011

Hi.

I am building a dialog box using ScriptUI, and need to dynamically display text entry boxes.

I am using the code below, and using doscript to help me:

for(i=1;i<=myNoOfFields;i++){     myString = ("mySettings" + i + "= myDetailsGroup.add(\"edittext\", undefined,(\"Style Sheet" + i +"\"));");     app.doScript(myString);     }

mystring becomes the line:

mySettings1= myDetailsGroup.add("edittext", undefined,("Style Sheet1"));

which is valid code as far as I can see, and if i manually typed this code it would be fine, but for some reason when triggered by the doScript, causes the error: "unknown object type"

Are there restrictions to not using doScript within scriptUI? or am I doing something very wrong fundamentally?

Thanks as always

Roy

TOPICS
Scripting
770
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 ,
Mar 03, 2011 Mar 03, 2011

I thought I'd solved it and converted 'i' to a string, but made no difference.

I have also tried passing the line:

"mySettings" + i + "= myDetailsGroup.add(\"edittext\", undefined,(\"Style Sheet" + i +"\"));"

straight into the doScript, but still nothing.

still pulling my hair out with this one!

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 ,
Mar 03, 2011 Mar 03, 2011

I found a couple of bad syntaxs' and changed them so the variable mySring =

mySettings1= myDetailsGroup.add("editText", undefined,"Style Sheet1");

Corrected edittext to editText, and got rid of unnecessary brackets.

but still nothing....

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 ,
Mar 03, 2011 Mar 03, 2011

I have now run the for loop and got this:

mySettings1= myDetailsGroup.add("editText", undefined,"Style Sheet 1");

mySettings2= myDetailsGroup.add("editText", undefined,"Style Sheet 2");

mySettings3= myDetailsGroup.add("editText", undefined,"Style Sheet 3");

and passed this string to the doScript with the same results.

This is contructed during the building of the dialog. I cannot see why this would not add 3 edit text entries to the dialog I am creating.

I can only come to the conclusion that I am unable to make dynamic fields in a dialog.  I am going to use plan b which is adding a multi line text entry, but would rather have used the technique above

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
LEGEND ,
Mar 03, 2011 Mar 03, 2011

This is a really bad approach.

It is tantamount to using "eval" in JavaScript. It is inefficient, error-prone, hard to debug, confusing to read, and potentially insecure (though not in this case). And there's no need for it!

If you want to add multiple edittext elements to your window, just add them in the loop -- don't use doScript when you can do what you want in the loop.

Instead, just use:

for (i=0; i<= myNoOfFields; i++) {

    myDetailsGroup.add("edittext", undefined, "Style Sheet"+i);

}

Now, it sounds like something else is wrong with your script, in the part you haven't shown us.

If you can give us a self-contained test case that doesn't work right, we can definitely help you!

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 ,
Mar 03, 2011 Mar 03, 2011

Hi.

Thanks for the response, but I am needing to also create text I can get hold of later, hense needing the 'mySettings1=' below.

mySettings1= myDetailsGroup.add("editText", undefined,"Style Sheet 1");

Is it possible to loop the variable also in the same way?  I will look into it later when I have some more time.
Thanks again
Roy

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
LEGEND ,
Mar 03, 2011 Mar 03, 2011
LATEST

Oh. Well, just use an array:

var mySettings = [];


for (i=0; i<= myNoOfFields; i++) {
    mySettings.push(
        myDetailsGroup.add("edittext", undefined, "Style Sheet"+i);
     );
}

And then just use mySettings[0] through mySettings[myNoOfFields].

Err, remember arrays are zero-indexes in JavaScript.

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