5 Replies Latest reply on Mar 15, 2016 9:46 AM by 1CM69

    Issues using && logical operator

    1CM69 Level 1

      Hi,

       

      I have a dialog that has 3 buttons on it.

       

      2 of the buttons are used to open Folder Select windows and the the last button is an OK button to action the script once the 2 folders have been selected.

       

      Here is a snippet of my code

       

      BTNg.OKBtn.enabled = false;
        
      DFgroup.DFBtn.onClick = function(){   
           DFdefault = new Folder(DARKinputFolder);   
           DFdefault = Folder.selectDialog('****Please Select The Folder Where Your DARK FRAMES Are Located****',DARKinputFolder);
           if ( DFdefault != null ) {
        DARKinputFolder = DFdefault.fsName.toString()
                             DFgroup.DFlabel.text = DARKinputFolder;
                             FolderChecker()
                           
        }
           }
      
      LFgroup.LFBtn.onClick = function(){   
           LFdefault = new Folder(LIGHTinputFolder);  
           LFdefault = Folder.selectDialog('****Please Select The Folder Where Your LIGHT FRAMES Are Located****',LIGHTinputFolder);
            if ( LFdefault != null ) {
        LIGHTinputFolder = LFdefault.fsName.toString()
                             LFgroup.LFlabel.text = LIGHTinputFolder;
                             FolderChecker()
        }
            }
      
      
      
      
      
      function FolderChecker(){
          if (DARKinputFolder !='' && LIGHTinputFolder !=''){// && LFdefault != null){
          BTNg.OKBtn.enabled = true;
          }
      }
      
      
      
      

      the OK button is DISABLED by default and I am trying to allow it to only be ENABLED once the 2 variables DARKinputFolder & LIGHTinputFolder are both not NULL.

      The problem is that if just one of these two variables is not NULL but the other is still NULL the button is being enabled regardless.

       

      I only want the button to be enabled when both criteria are met.

       

      Regards..,

        • 1. Re: Issues using && logical operator
          Chuck Uebele Adobe Community Professional & MVP

          You need to use the or operator. Try using:

           

          if (!DARKinputFolder || !LIGHTinputFolder){// && LFdefault != null){

           

          or

           

          if (!DARKinputFolder.exists || !LIGHTinputFolder.exists){// && LFdefault != null){
          • 2. Re: Issues using && logical operator
            1CM69 Level 1

            Hi,

             

            thanks for replying.

             

            I have tried both your suggestions but it is still not functioning as I wish.

             

            the 1st option you suggested, result:

            ******

            at startup - OK button disabled

            I choose a folder in DARKinputFolder dialog - OK button still disabled (this is good as I require the user to choose a folder in both dialogs before the OK button becomes active.)

            I choose a folder in LIGHTinputFolder dialog - OK button is still disabled (this is not good, both variables; DARKinputFolder & LIGHTinputFolder are now populated, the OK button needs to be ENABLED.)

            ******

             

            the 2nd option you suggested, result:

            ******

            at startup - OK button disabled

            I choose a folder in DARKinputFolder dialog - OK button becomes ENABLED (this is not good, the OK button should not be ENABLED until both variables; DARKinputFolder & LIGHTinputFolder have been populated.)

            I did not need to go any further with this example.

            ******


            regards..,

            • 3. Re: Issues using && logical operator
              1CM69 Level 1

              OK,

               

              with a bit of fiddling it looks like I have a result, here's what I used:

               

              function FolderChecker(){
                 if (DFdefault.exists && LFdefault.exists){
                  BTNg.OKBtn.enabled = true;
                  }
              }
              

               

              this seems to work perfectly.

               

              Thanks for pointing me in the correct direction.

              • 4. Re: Issues using && logical operator
                SuperMerlin Level 5

                The problem you were having is because when the first FolderChecker() is called one of the variables is undefined.

                To correct this you should define both variables first:-

                LIGHTinputFolder = '';

                DARKinputFolder = '';

                • 5. Re: Issues using && logical operator
                  1CM69 Level 1

                  hi,

                   

                  thanks for replying.

                   

                  Both variable are defined earlier in the code, just not shown in the snippet I posted.

                   

                  I have resolved the issue now but thanks for your input.

                   

                  Regards