We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36760
    • 136 Posts
    I'm going to try to explain this the best I can.

    I have one MIGX TV called guideTalentBuildNames with the following tab setup:
    [
    {"caption":"Build", "fields": [
        {"field":"build-name","caption":"Build Name"}
    ]}
    ]


    I have a second MIGX TV called guideTalentBox with the following tab setup:
    [
    {"caption":"Spell Box", "fields": [
    {"field":"talent-name","caption":"Talent Name"},
    {"field":"talent-anchor","caption":"Talent Anchor Name"},
    {"field":"talent-spell-id","caption":"Talent Spell ID"},
    {"field":"talent-icon-url","caption":"Talent Icon URL","inputTVtype":"image"},
    {"field":"talent-recommendation","caption":"Recommendation","inputTV":"guideTalentBoxRecommendation"},
    {"field":"good-for","caption":"Good For","inputTVtype":"migx"},
    {"field":"long-description","caption":"Long Description","inputTVtype":"richtext"}
    ]}
    ]


    Both of these TVs exist on the same template. I'm hoping to add the builds from the guideTalentBuildNames TV as fields in the guideTalentBox TV with the following setup:
    {"field":"talent-recommendation-[[+build-name]]","caption":"[[+build-name]] Recommendation","inputTV":"guideTalentBoxRecommendation"}


    I came across this thread https://forums.modx.com/thread/96322/migx-howto-populate-dynamically-form-tabs-and-grid-columns, but I'm having trouble following the steps and can't tell if it's quite what I want to do as the OP wanted all the fields dynamically generated.

    I'm on MODX Revolution 2.5.5-pl, with MIGX 2.9.6-pl.

    I appreciate any help or nudges in the right direction!

      • 4172
      • 5,888 Posts
      should work with a config-file, like that (much the same, like the example of the other thread):

      <?php
      $resource_id = $this->modx->getOption('resource_id', $_REQUEST, '');
      $resource_id = empty($resource_id) ? $this->modx->getOption('id', $_REQUEST, '') : $resource_id;
      if ($resource = $this->modx->getObject('modResource', $resource_id)) {
          $buildnames = $this->modx->fromJson($resource->getTVValue('guideTalentBuildNames'));
          $columns = $this->customconfigs['columns'];
          $fields = array();
          if (is_array($buildnames)) {
              foreach ($buildnames as $buildname) {
                  $field = $column = array();
                  $name = $this->modx->getOption('build-name', $buildname, '');
                  $field['caption'] = $column['header'] = $name . ' Recommendation';
                  $field['field'] = $column['dataIndex'] = 'talent-recommendation-' . $name;
                  $field['inputTV'] = 'guideTalentBoxRecommendation';
                  $columns[] = $column;
                  $fields[] = $field;
              }
          }
          $tabs = $this->customconfigs['tabs'];
          //add a new tab
          $tabs[] = array('caption' => 'Recommendations', 'fields' => $fields);
          $this->customconfigs['tabs'] = $tabs;
          //add new columns - if you don't want new columns, remove this line
          $this->customconfigs['columns'] = $columns;
      }
      


      of course, they need to save and reload the manager-resource-page after adding guideTalentBuildNames, before they are added as fields to the other TV [ed. note: Bruno17 last edited this post 7 years, 1 month ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 36760
        • 136 Posts
        Thank you for the code! I guess my confusion was mostly with where/how to put everything together. I have a feeling I'm missing something obvious!

        1) I go to the Extras tab > MIGX > MIGX configs tab > create a new item with the name "guideTalentBox" and unique MIGX ID "guideTalentBox"
        2) Go to Formtabs, add a new tab
        3) Add all my static fields to the tab
        4) This is where I get lost - do I create a new field for the dynamic fields and put something in the "Configs" box to point to the config file? Or, am I supposed to create a completely separate MIGX config or TV to handle the config file, and then put that name in?

        Something just isn't clicking with me no matter how many times I read the other thread!
          • 4172
          • 5,888 Posts
          Add the static fields to your tab
          Create a config-file with the code above, which has the same name, like your config, in your case
          guideTalentBox.config.inc.php

          the script takes your existing static tabs

          $tabs = $this->customconfigs['tabs'];
          


          and adds a new tab with your dynamic fields

              $tabs[] = array('caption' => 'Recommendations', 'fields' => $fields);
              $this->customconfigs['tabs'] = $tabs;
          



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

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!