We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38142
    • 91 Posts
    In MODX Revo 2.4.2 I have created a template variable to categorise resources, with Input Type as Listbox(multi-select) and this for the Input Option Values:

    @EVAL return $modx->runSnippet('listMyResources',array('parent' => 26));


    to populate the drop down with categories pulled from a list of resource page titles.

    Everything works, i.e. the categories appear in the TV drop-down on the resources to be categorised, and when selected and the resource is saved the selection is saved in the database, BUT on page refresh the chosen categories disappear from the TV field on the resource that has been categorised. The category selection is still there in the database, but is no longer visible on the resource.

    Does anyone know how to stop the TV selection disappearing after page refresh?

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

    • discuss.answer
      • 3749
      • 24,544 Posts
      It sounds like a cache issue.

      Can you post the full tag that shows the list?
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 38142
        • 91 Posts
        Bob, yes, you are right, it does seem to be a caching issue. Just tried saving a new selection of template values on a resource, then refreshed the page and saw again that the new selection is not being shown in the field on the resource. But after deleting all the cache folders for the core in CPanel, then refreshing the page, the TV values appear.

        Is there some way of stopping the caching of those TV values when setting up the template variable?
          • 3749
          • 24,544 Posts
          Can you post the full tag that shows the list?

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 38142
            • 91 Posts
            Sorry, Bob, for not understanding what "the full tag" refers to in this context. Do you mean the snippet listMyResources that is populating the Input Options for the TV? If so, it is:

            $parent = $modx->getOption('parent',$scriptProperties,26);
            $parentObj = $modx->getObject('modResource',$parent);
            if (!($parentObj instanceof modResource)) { return ''; }
            $resArray = $parentObj->getMany('Children');
            $resources = array();
            foreach($resArray as $res) {
              if ($res instanceof modResource) {
                $resources[] = $res->get('pagetitle') ;
              }
            }
            $out = implode("||",$resources);
            return $out;


            Thank you very much for taking the time to help, yet again.
              • 40045
              • 534 Posts
              Maybe getMany() is guilty, remember some strange behaviour with getOne() getMany(), what happens if you try instead:

              $out = '';
              $parent = $modx->getOption('parent',$scriptProperties,26);
              $childObjs = $modx->getCollection('modResource', array('parent' => $parent));
              
              $resources = array();
              
              foreach($childObjs as $res) {
                  $resources[] = $res->get('pagetitle') . '==' . $res->get('id');
              }
              
              if (!empty($resources) {
                $out = implode("||",$resources);
              }
              
              return $out;
              


              ...when rewriting the code I got your issue, has nothing to do with getMany()...you need to give the Listbox a label==value combination as list items, you just had the label in place, so the tv doesn't know what to save into the db I guess...
                • 3749
                • 24,544 Posts
                No, I meant the MODX tag that goes on the page where the list appears. It looks like exside may have solved your problem, though.

                Note that his code will be faster, but will only work if the children are immediate children (iow, there are never any "grandchildren").
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 38142
                  • 91 Posts
                  Thank you, Exside, for improving the snippet and correcting my omission of the option==value pairings. You said that the TV wouldn't have known what to save in the database, but I could see from PHPMyAdmin that the right selections were being saved in the database; they just weren't being shown on the resource in the manager area after page refresh. Now I am using exactly the snippet you suggested (definitely better), the right options are being shown in the drop-down list on the resource, and the selections are being saved to the database. They still disappear on the resource (not the database) on page refresh.

                  Bob, the list of categories is pulled from a list of resource pagetitles that are children, where there are no grandchildren.

                  There is no tag used in a template for the front end of the website. This is a TV used simply to categorise resources so that they can then be searched using a TVfilter with getResources, which works.

                  It seems to be a browser issue. I am using Firefox (version 42.0, apparently), and if I press CTRL-F5 the right TV values appear in the resource. Odd that other TV values show normally without having to use CTRL-F5. Guess it is a purely Firefox issue, not a MODX bug or something missing from the snippet.

                  Thank you again, Bob and Exside, for the help.
                    • 40045
                    • 534 Posts
                    That's weird indeed, does it work on chrome? When I read your first post I actually was thinking (when finding the non-value issue) how the right value got into the db anyways^^...
                      • 38142
                      • 91 Posts
                      Sorry for the delay in replying. No, the weirdness disappears in Chrome. Stupid of me not to check in a second browser right at the beginning. I checked IE after Bob's suggestion and saw that in IE the TV field on the resource page was working normally, so it clearly was a problem with Firefox, not with MODX. As for the database getting the necessary information, clearly the snippet only needs to get one value, which is then assumed to hold for both the bits of the value-option pair in the selection drop-down list.

                      Thanks again for taking the time to help.