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

    I would like to know how to render a value of an option, like :

    form
    [{
    	"caption":"Attribute",
    	"fields":[
    		{
    			"field":"activeSnippet",
    			"caption":"Module",
    			"inputTVtype":"listbox",
    			"inputOptionValues":"Secteurs==1||Contenu==2"
    		}
    	]
    }]
    


    tab
    [
    	{
    		"header": "Module actif",
    		"width": "30",
    		"sortable": "true",
    		"dataIndex": "activeSnippet"
    	}
    ]
    


    If I choose "Secteurs" I would like to record "1" but show on the grid "Secteurs", don't know how to !

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

      Low
      • 4172
      • 5,888 Posts
      this is one way:
      Do your config for your TV with the MIGX - configurator - CMP

      Create a config for your TV with formtabs and colums
      You can put your options into a chunk 'inputoptions_snippets' with:

      Secteurs==1||Contenu==2
      

      have inputoption values:

      @CHUNK inputoptions_snippets


      To render the text, create another column with another unused fieldname, for example:

      "dataIndex": "renderSnippet"


      select the renderer 'this.renderChunk' for that column

      with a render-tpl like

      [[renderActiveSnippet? &snippet=`[[+activeSnippet]]`]]


      the snippet-code of renderActiveSnippet should be like:

      $snippet = $modx->getOption('snippet',$scriptProperties,'');
      $inputoptions = $modx->getChunk('inputoptions_snippets');
      
      $snippets = explode('||',$inputoptions);
      foreach ($snippets as $snippetoption){
          $snippetoption_parts = explode('==',$snippetoption);
          $value = isset($snippetoption_parts[0]) ? $snippetoption_parts[0] : '';     
          $text = isset($snippetoption_parts[1]) ? $snippetoption_parts[1] : $value;
          if ($snippet == $value){
              return $text;
          }
      }
      return '';















        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 17546
        • 75 Posts
        Thanks for you post ! But I never user MIGX config, I think I must follow step by step how your addons works before do it ! Is there any tuto on your website or other screencast can be help me ?

        Mode noob on for this addons !
          Low
          • 4172
          • 5,888 Posts
          go the MIGX - CMP

          Create a new Configuration with a name, for example 'activesnippets'
          put this same name into the field 'unique MIGX id'

          then go to the tab formtabs
          Create a tab
          and your fields in the tab

          Go to the tab columns
          Create your columns

          use that name 'activesnippets'
          in the configs - field of your TV and let the formtabs and columns - fields empty

          That's it, basically

          Now you can setup everything for your MIGX-TV within your configuration like descriped above.





            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 17546
            • 75 Posts
            Hello,

            I'll try your directive ! Thanks.
            See you later smiley
              Low
              • 17546
              • 75 Posts
              Quote from: Bruno17 at Aug 03, 2015, 01:45 PM
              this is one way:
              $snippet = $modx->getOption('snippet',$scriptProperties,'');
              $inputoptions = $modx->getChunk('inputoptions_snippets');
              
              $snippets = explode('||',$inputoptions);
              foreach ($snippets as $snippetoption){
                  $snippetoption_parts = explode('==',$snippetoption);
                  $value = isset($snippetoption_parts[0]) ? $snippetoption_parts[0] : '';     
                  $text = isset($snippetoption_parts[1]) ? $snippetoption_parts[1] : $value;
                  if ($snippet == $value){
                      return $text;
                  }
              }
              return '';


              The ligne :
              $snippet = $modx->getOption('snippet',$scriptProperties,'');
              


              Return a row result, I must parse it before translate id to string, like :

               [{"MIGX_id":"1","activeSnippet":"2"},{"MIGX_id":"2","activeSnippet":"99"},{"MIGX_id":"3","activeSnippet":"1"}]
              


              But I think I understand now how to do ! I use the modx->fromJSON to parse the raw result and return the correct value, if it work, I publish the code here for example / feedback !
                Low
                • 17546
                • 75 Posts
                Just for info !
                When I use MIGX, I always create MIGX TV in manual way, create from raw json, not by the MIGX Management, I don't know how to use it ! (maybe because I never used it before).

                When you write :
                select the renderer 'this.renderChunk' for that column

                with a render-tpl like
                [[renderActiveSnippet? &snippet=`[[+activeSnippet]]`]]
                
                I don't know where to put this [[renderActive....]] code in the json Gris Columns.

                [
                    {
                        "dataIndex": "activeSnippet",
                        "header": "Module actif",
                        "sortable": "true",
                        "width": "30"
                    },
                    {
                        "dataIndex": "renderSnippet",
                        "header": "Render value test",
                        "sortable": "true",
                        "renderer": "this.renderChunk",
                        "???": "[[!renderActiveSnippet? &snippet=`[[+activeSnippet]]`]]",
                        "width": "30"
                    }
                ]
                

                  Low
                • discuss.answer
                  • 37047 ☆ A M B ☆
                  • 309 Posts
                  Quote from: low at Aug 04, 2015, 06:59 PM
                  Just for info !
                  When I use MIGX, I always create MIGX TV in manual way, create from raw json, not by the MIGX Management, I don't know how to use it ! (maybe because I never used it before).

                  I have never used the configurator either, and have not found any clear tutorial in English on how to use it. Would like to learn, but in the mean time here is what I did just using the TV Form and Grid json. I had a similar issue as you with radio options and this is how I solved it (using bits of advice I found all over the forums.) Bruno may pop in here and tell me I'm heading down crazy street, but for now my solution works.

                  Originally I had regular Title==value pairs. But I needed to be able to use the title in the grid columns instead of the value, and also use the value as a classname in the HTML.

                  For my radio buttons in the form tab:
                  {"field":"nbsType","caption":"Choose Event Type", "inputTVtype":"option","inputOptionValues":"Rehearsal==Rehearsal:rhs||No Rehearsal==No Rehearsal:no-rhs||Concert==Concert:concert","default":"Rehearsal:rhs"}


                  So instead using a Title==Title:value syntax combined with the renderFirst renderer (included in MIGX), and custom output modifiers for the front end template (see renderFirst and renderSecond snippets below) I can control which part is used.

                  The Grid columns looks like this (uses the first part so displays the title):
                  {"header": "Event Type", "width": "50", "sortable": "false", "dataIndex": "nbsType","renderer":"this.renderFirst"}


                  The template looks like this (uses the second part for a class on the row, uses the first part to display in the table cell):
                  <tr class="[[+nbsType:renderSecond]]">
                    <td>[[+nbsType:renderFirst]]</td>
                    <td>other fields...</td>
                    <td>other fields...</td>
                  </tr>


                  The snippets-- I found the renderSecond snippet somewhere in these forums and will link to it when I find it again.* Copied it to make renderFirst snippet.

                  renderFirst
                  <?php
                  $val = explode(':',$input);
                  return $val[0];


                  renderSecond
                  <?php
                  $val = explode(':',$input);
                  return $val[1];


                  *Edit: here's the original post from Bruno himself, although a solution from 4 years ago...
                  https://forums.modx.com/thread/41006/migx---multiitemsgridtv-for-modx---revolution?page=12#dis-post-236932 [ed. note: lucy last edited this post 11 years, 2 months ago.]
                    Lucy Iannotti
                    Following Sea design & development
                    http://www.following-sea.com
                    New Bedford, MA
                    • 17546
                    • 75 Posts
                    Hello Lucy, I'll try your solution, thanks !

                    But, maybe the better way is to make the listbox like (better = quick solution):
                    one==one||two==two|three==three
                    

                    ... but, well, I prefer numeric ref !
                      Low
                      • 17546
                      • 75 Posts
                      Feedback : The last solution is the best (and easy) way !
                      Just do a list/explode in my snippet and all works fine (back and front end).

                      Thanks you all !
                        Low