We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45613
    • 45 Posts
    I am following the "Adding a Custom TV type - MODX 2.2" tutorial. The tutorial works just fine, except for one small problem. When you display the template selected in the front end, it just shows the ID number. It does the same thing, when after you save the resource page, and go back to the Template Variables, it shows the ID - like 12, rather than the name.

    When I select the templates from the list, the first time, it gives the complete list. Just after the save, going back to the template variables screen, it just has the ID. If I click the list to select another, it shows the entire list.

    So, is there a change to the templateselect.tpl that would fix this?
    and a change to the OutputRender to display the name not the value?

    Thanks,
    bill

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

      • 4172
      • 5,888 Posts
      for the frontend, you can install pdoTools, which doesn't matter anyway to have it installed, and try this:

      [[pdoField? &class=`modTemplate` &id=`[[*yourTemplateTV]]` &field=`templatename`]]

      the other issue, is, when you have a paginated listbox, and the selected value is not on the first page, the listbox doesn't know the name of the selected value.

      you would need to figure out the page of the selected value serverside and open this page by default.

      Happy coding!
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 45613
        • 45 Posts
        Quote from: Bruno17 at Jan 20, 2014, 05:27 AM

        the other issue, is, when you have a paginated listbox, and the selected value is not on the first page, the listbox doesn't know the name of the selected value.

        you would need to figure out the page of the selected value serverside and open this page by default.

        when I select the listbox to see all the possible selections, it is fine. It is the displaying of selected that is not working. It is like the "uses template" box on the "document" tab for a resource. It should list the name. I guess I may have to try to find the code that displays this panel / widget.

        Any suggestions on where to look?
        • discuss.answer
          • 45613
          • 45 Posts
          I finally figured out the answer. The core/components/ourtvs/tv/input/tpl/templateselect.tpl needs to be changed to
          <select id="tv{$tv->id}" name="tv{$tv->id}" class="combobox"></select>
          <script type="text/javascript">
          // <![CDATA[
          {literal}
          Ext.onReady(function() {
              MODx.load({
          {/literal}
                  xtype: 'modx-combo-template'
                  ,name: 'tv{$tv->id}'
                  ,hiddenName: 'tv{$tv->id}'
                  ,transform: 'tv{$tv->id}'
                  ,id: 'tv{$tv->id}'
                  ,width: 300
                  ,value: '{$tv->value}'
          {literal}
                  ,listeners: { 'select': { fn:MODx.fireResourceFormChange, scope:this}}
              });
          });
          {/literal}
          // ]]>
          </script>
          


          The key is that you have to put this inside the onReady Function to load this. If this loads before everything is initialized, then the request for the list of templates will fail with access denied. The MODAUTH information is needed to validate the request, which is automatically added when loaded from the onReady function.

          Once it has gotten the results, then it will display the template name.

          If you are using modx-combo and your own url and getlist, it works exactly the same. You have to load this in the onReady function.

          Another trick I learned about modx-combo is that there is a config variable called "displayName". This is the db field name that you want displayed. It will use the id field as the value stored, but to display a human readable string it uses the field stored in "displayName". By default it is "name". but for modx-combo-template it is set to templateName.

          Hopefully this helps others.