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

Disable editText when DropDownList selected

Community Beginner ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

Hi everyone!

I'm trying to write my first script. I don't know how to disable my EditText when select one item in DropDownList.

Anyone can help me out with it?
sorry about my english. thanks a lot!

here is the script UI

function createUserInterface (thisObj,userInterfaceString,scriptName){

    var pal = (thisObj instanceof Panel) ? thisObj : new Window("palette", scriptName,

  undefined,{resizeable: true});

    if (pal == null) return pal;

   

    var UI=pal.add(userInterfaceString);

          UI.myTabbedPanel.tabPoint.myGroup1.PointDropDownList.selection = 1;

   

    pal.layout.layout(true);

    pal.layout.resize();

    pal.onResizing = pal.onResize = function () {

        this.layout.resize();

    }

    if ((pal != null) && (pal instanceof Window)) {

            pal.show();

  }

    return UI;

};

var resourceString =

"group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['left', 'top'],\

                     myIconButton: IconButton{text:'My website', image:'~/Desktop/logo/icon2.jpg'},\

                     myTabbedPanel: Panel{type:'tabbedpanel', orientation:'left', alignChildren:['left', 'fill'],\

                           tabPoint: Panel{type:'tab', text:'Point', orientation:'column',alignment:['left','top'],\

                                myGroup1: Group{orientation:'row', alignment:['left','top'],\

                                    myStaticText: StaticText{text:'Select Point Number'},\

                                    PointDropDownList: DropDownList{properties:{items:['1 Point', '2 Points','3 Points', '4 Points', '5 Points', '6 Points']}},\

                                },\

                                myGroup2: Group{orientation:'row', alignment:['left','top'],\

                                    myGroupPointRow1: Group{orientation:'column', alignment:['left','top'],\

                                        myEditTextPoint1: EditText{text:'Cut 1 Point ', alignment:['left','top'], characters:11},\

                                        myEditTextPoint3: EditText{text:'Cut 3 Point ', alignment:['left','top'], characters:11},\

                                        myEditTextPoint5: EditText{text:'Cut 5 Point ', alignment:['left','top'], characters:11},\

                                    },\

                                    myGroupPointRow2: Group{orientation:'column', alignment:['left','top'],\

                                        myEditTextPoint2: EditText{text:'Cut 2 Point ', alignment:['left','top'], characters:11},\

                                        myEditTextPoint4: EditText{text:'Cut 4 Point ', alignment:['left','top'], characters:11},\

                                        myEditTextPoint6: EditText{text:'Cut 6 Point ', alignment:['left','top'], characters:11},\

                                    },\

                                },\

                                myGroup3: Group{orientation:'row', alignment:['left','top'],\

                                    myCheckbox: Checkbox{text:'Keep your layer selection'},\

                                },\

                         },\

                         tabMarker: Panel{type:'tab', text:'Marker', orientation:'column',\

                         },\

                     },\

                myButton2: Button{text:'Apply', alignment:['right','buttom']},\

          }"

         

var UI = createUserInterface(this,resourceString,"Trim Layers");

// I have tried this, but error

UI.myGroup.myTabbedPanel.tabPoint.myGroup1.PointDropDownList.selection[2].onClick = function () {

       UI.myGroup.myTabbedPanel.tabPoint.myGroup2.myGroupPointRow1.myEditTextPoint1.enabled = !this.value;

}

TOPICS
Scripting

Views

420

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
Enthusiast ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

Here's a simplified example that should help you out:

function createUserInterface (thisObj,userInterfaceString,scriptName){

  var resourceString =

"group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['left', 'top'],\

PointDropDownList: DropDownList{properties:{items:['1 Point', '2 Points','3 Points', '4 Points', '5 Points', '6 Points']}},\

myEditTextPoint1: EditText{text:'Cut 1 Point ', alignment:['left','top'], characters:11},\

}";

     var pal = (thisObj instanceof Panel) ? thisObj : new Window("palette", scriptName, undefined,{resizeable: true});

     if (pal == null) return pal;

  

     pal.grp =pal.add(resourceString);

    

     pal.grp.PointDropDownList.onChange = function() {

          pal.grp.myEditTextPoint1.enabled = (this.selection.index != 2) // i.e. enabled if 3 Points isn't selected

     };

     pal.layout.layout(true);

     pal.layout.resize();

     pal.onResizing = pal.onResize = function () {

          this.layout.resize();

     }

     if ((pal != null) && (pal instanceof Window)) {

          pal.show();

     }

     return UI;

};

var UI = createUserInterface(this,resourceString,"Trim Layers");

Votes

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
Community Beginner ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

thanks for the quick response. It worked

Votes

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
Community Beginner ,
Mar 24, 2017 Mar 24, 2017

Copy link to clipboard

Copied

I tried but It didn't work work for all 3  (1 Point, 2 Points, 3 Points) 

1 Point: enabled All   (No)

2 Points: enable "cut 1 Point" "cut 2 Point" (No)

3 Points: enable only "cut 3 Point" (YES)

I don't know any syntax to fix this error. Can you help me one more?

function createUserInterface (thisObj,userInterfaceString,scriptName){

    var pal = (thisObj instanceof Panel) ? thisObj : new Window("palette", scriptName,

  undefined,{resizeable: true});

    if (pal == null) return pal;

    var UI = pal.add(userInterfaceString);

    UI.myTabbedPanel.tabPoint.myGroup1.PointDropDownList.selection = 1

          UI.myTabbedPanel.tabPoint.myGroup1.PointDropDownList.onChange = function () {         

                  UI.myTabbedPanel.tabPoint.myGroup2.myGroupPoint.myEditTextPoint2.enabled = (this.selection.index != 0)

                  UI.myTabbedPanel.tabPoint.myGroup2.myGroupPoint.myEditTextPoint3.enabled = (this.selection.index != 0)

                 

                  UI.myTabbedPanel.tabPoint.myGroup2.myGroupPoint.myEditTextPoint1.enabled = (this.selection.index != 1)

                  UI.myTabbedPanel.tabPoint.myGroup2.myGroupPoint.myEditTextPoint3.enabled = (this.selection.index != 1)

                 

                  UI.myTabbedPanel.tabPoint.myGroup2.myGroupPoint.myEditTextPoint1.enabled = (this.selection.index != 2)

                  UI.myTabbedPanel.tabPoint.myGroup2.myGroupPoint.myEditTextPoint2.enabled = (this.selection.index != 2)

           }       

    pal.layout.layout(true);

    pal.layout.resize();

    pal.onResizing = pal.onResize = function () {

        this.layout.resize();

    }

    if ((pal != null) && (pal instanceof Window)) {

            pal.show();

  }

    return UI;

};

var resourceString =

"group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['left', 'top'],\

                     myIconButton: IconButton{text:'My website', image:'~/Desktop/logo/icon2.jpg'},\

                     myTabbedPanel: Panel{type:'tabbedpanel', orientation:'left', alignChildren:['left', 'fill'],\

                           tabPoint: Panel{type:'tab', text:'Point', orientation:'column',alignment:['left','top'],\

                                myGroup1: Group{orientation:'row', alignment:['left','top'],\

                                    myStaticText: StaticText{text:'Select Point Number'},\

                                    PointDropDownList: DropDownList{properties:{items:['1 Point', '2 Points','3 Points']}},\

                                },\

                                myGroup2: Group{orientation:'row', alignment:['left','top'],\

                                    myGroupPoint: Group{orientation:'column', alignment:['left','top'],\

                                        myEditTextPoint1: EditText{text:'Cut 1 Point ', alignment:['left','top'], characters:11},\

                                        myEditTextPoint2: EditText{text:'Cut 2 Point ', alignment:['left','top'], characters:11},\

                                        myEditTextPoint3: EditText{text:'Cut 3 Point ', alignment:['left','top'], characters:11},\

                                    },\

                                },\

                         },\

                     },\

          }"
var UI = createUserInterface(this,resourceString,"Trim Layers");

Votes

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
Enthusiast ,
Mar 24, 2017 Mar 24, 2017

Copy link to clipboard

Copied

LATEST

I don't even have to really study this to see it's a flaw in your logic, not the syntax. You've got multiple lines that specifically set each textbox's enabled setting so its only the last one that will stick.

You can either do something like:

myEditTextPoint1.enabled = (THIS CONDITION && THIS CONDITION);

myEditTextPoint2.enabled = (THIS CONDITION && THIS CONDITION);

You set enabled through true/false so it's just whether the resulting conditions are true/false.

or

if (this.selection.index == 0) {

     myEditTextPoint1.enabled = true;

     myEditTextPoint2.enabled = false;

     myEditTextPoint2.enabled = false;

} else if (this.selection.index == THIS) {

     DO ALL THESE THINGS INSTEAD

} else {

      DO ALL THESE THINGS INSTEAD

}

Obviously this code is just an example for explanation and you'll have to fill it in properly. Figuring out logic is an important part of learning to code.

Votes

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