We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11975
    • 2,542 Posts
    Hi,

    Will it be possible in the future to link TV with another one.
    For instance when you specify a location.
    In the first select you get the state (california, texas, ...)
    and in the second a town list, this one remains empty until you have specified the first condition

    For now I’ve been able with @SELECT to link the TVs but I get an error in the backoffice. The error only concerns the document and doesn’t affect the folder huh

    Anyway you have to save first TV before getting the right values in the second one. This issue doesn’t exist in the front end because of the reloading after changing the first value.

    hope that makes sense.

    :-)
      Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
      • 22815
      • 1,097 Posts
      Is there a way of coding the 2nd TV so that it returns blank if the 1st TV is blank?
        No, I don't know what OpenGeek's saying half the time either.
        MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
        Forum: Where to post threads about add-ons | Forum Rules
        Like MODx? donate (and/or share your resources)
        Like me? See my Amazon wishlist
        MODx "Most Promising CMS" - so appropriate!
        • 11975
        • 2,542 Posts
        Hi,

        here is my code. I made a mistake in the post above , I use @EVAL instead of @SELECT

        <?php //for highlighting
        @EVAL $none = "aucune==";
        $docID = $modx->getDocumentIdentifier('id');
        $templateTest = $modx->getTemplateVar('templateTest','*', $docID);
        if(strlen($templateTest['value'])>0){
        $sql= "SELECT aliment, idaliment FROM modx_aliments WHERE groupe=".$templateTest['value']." ORDER by aliment ASC";
        $rs = $modx->db->query($sql);
        $value="";
        while($myvalues = $modx->db->getRow($rs)) {
        $value .= $myvalues['aliment']."==".$myvalues['idaliment']."||";
        }
        return substr($value,0,-2);
        }else{
        return $none;
        }
        


        :-)

        EDIT: I forgot to answer your question. with the code above if the first is blank we send back a dummy value to the second.
          Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
          • 11975
          • 2,542 Posts
          This code works (needs some cleaning) both in frontend and backend.
          Of course in the backoffice you have to save before editing the second one.


          <?php //highlight
          @EVAL  
          $docID = $modx->documentIdentifier;
          if(!empty($docID)){
              $templateTest = $modx->getTemplateVar('templateTest','*', $docID);
              if(strlen($templateTest['value'])>0){ 
                  $sql= 'SELECT aliment, idaliment FROM modx_aliments WHERE groupe='.$templateTest['value'].' ORDER by aliment ASC';
                  $value='';
                  $rs = $modx->db->query($sql);
                      while($myvalues = $modx->db->getRow($rs)) {
                      $value .= $myvalues['aliment'].'=='.$myvalues['idaliment'].'||';
                      }
                  return substr($value,0,-2);
              }
          }else{
          $value = 'none==';
          return $value;
          } 
          
          


          EDIT: well, in fact it doesn’t. I don’t have erros any more but the values are not shown in second TV
          still investigating.
            Made with MODx : [url=http://www.copadel.com]copadel, fruits et l