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

    I have a question about the TV - input type: listbox(single-select) (input option values). Inside this input option values, I have: Amsterdam||London||NewYork||Brussel||Paris. This will create a listbox in the back-end. Now I want to know or it is possible to have this on the front-end. Do I need a snippet or is there any plugin for this.

    Thanks for your time.

    Using MODX Revolution 2.1.3-pl (traditonal)

    This question has been answered by Bruno17. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      <select name="filter_name">
      [[!getTvOptions? &tpl=`filterSelectOption` &tvname=`selectTV` &name=`filter_name`]]
      </select>
      


      snippet getTvOptions:
      //[[getTvOptions? &tpl=`myChunk` &tvname=`myTv` &name=`cb1`]]
       
      $tv = $modx->getObject('modTemplateVar',array('name'=>$tvname));
      $options = explode('||',$tv->get('elements'));
       
      foreach ($options as $option){
          $opt = explode ('==',$option);
          $ph['value'] = count($opt)>1 ? $opt[1]: $opt[0];
          $ph['text'] = $opt[0];
          $ph['name'] = !empty($asArray) ? $name.'[]' : $name;
          $ph['checked'] = ''; 
          $ph['selected'] = '';
          
          if ((is_array($_REQUEST[$name]) && in_array($ph['value'],$_REQUEST[$name])) || $_REQUEST[$name] == $ph['value']){
      
              $ph['checked'] = 'checked="checked"'; 
              $ph['selected'] = 'selected="selected"';      
             
          }
      
          $output .= $modx->getChunk($tpl,$ph);
      }
       
      return $output;
      


      chunk for normal use:
      <option value="[[+value]]" [[+selected]]>[[+text]]</option>
      


      for use with formit:

      <option value="[[+value]]" [[!+fi.[[+name]]:FormItIsSelected=`[[+value]]`]]>[[+text]]</option>
      

      [ed. note: Bruno17 last edited this post 12 years, 2 months ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 37213
        • 25 Posts
        Thanks for your kindly help Bruno, it works like a charm.

        [!getTvOptions? &tpl=`filterSelectOption` &tvname=`selectTV` &name=`filter_name`]]
        must be 
        [[!getTvOptions? &tpl=`filterSelectOption` &tvname=`selectTV` &name=`filter_name`]]
        


        One [ was missing,
          • 53244
          • 1 Posts
          easy, and worked

          
              //if ((is_array($_REQUEST[$name]) && in_array($ph['value'],$_REQUEST[$name])) || $_REQUEST[$name] == $ph['value'])
              
              if ($ph['name']==$ph['value'])
              {
                  $ph['checked'] = 'checked="checked"'; 
                  $ph['selected'] = 'selected="selected"';      
              }
           
              $output .= $modx->getChunk($tpl,$ph);
          }
            
          return $output;