We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37108
    • 80 Posts
    I've created a plugin that sets a value on a particular TV when a related TV has content in it (during OnDocFormSave). A problematic fine point is that when a user has "continue editing" set for the save behavior, updates made via the plugin are not visible (until one manually reloads the page they are editing). Is it possible to initiate the reloading of the active form via my plugin?
      • 3749
      • 24,544 Posts
      You could try adding something like this to the end of your plugin:

      $url = 'http://yoursite.com/manager/?a=30&id=' . $docId;
      $modx->sendRedirect($url);
        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
        • 37108
        • 80 Posts
        Thanks, Bob, for the idea. However, this causes the manager page to hang with the never-ending saving dialog. I'm guessing this is because of the sequence of execution (e.g., the actual saving is done after this plugin is fired, right?). Is there a different event in my plugin I should try this redirect within?
          • 3749
          • 24,544 Posts
          No, OnDocFormSave fires after the record is saved (as opposed to OnBeforeDocFormSave), but the JS code that works the save progress bar may be confused by what you're doing. Maybe the $_POST values are still set and it's trying to save the resource again.

          I'm not sure what the solution would be. You could try adding this line before the redirect, but I'm not sure it will help:

          $_POST = array();
            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
          • Not a complete solution but it may help ... this OnDocFormRender plugin modifies the success method of the resource panel to reload the page after save regardless if 'Continue' is selected, maybe you could build some logic around it for your use case:

            <?php
            $modx->regClientStartupHTMLBlock('
                <script type="text/javascript">
                        Ext.override(MODx.panel.Resource, {
                            originalSuccess: MODx.panel.Resource.prototype.success
                            ,success: function(o) {
                                this.originalSuccess(o);
                                var tv = Ext.get("tv1").dom.value;
                                if (tv && tv == "1") {
                                    MODx.loadPage(location.href);
                                }
                            }
                        });
                </script>    
            ');


            EDIT: Modified original code to show how you can access a TV value and only reload the page if a certain TV value is present. [ed. note: garryn last edited this post 10 years, 1 month ago.]
              Garry Nutting
              Senior Developer
              MODX, LLC

              Email: [email protected]
              Twitter: @garryn
              Web: modx.com
              • 37108
              • 80 Posts
              OK, looping back around to this subject long after the original query ...

              Garry's suggestion above worked with a tweak or two. I had to adjust the value sent to the MODx.loadPage method, as it seems to require the action and resource id taken from the query string (in this case "resource/update&id=[nnn]"):
              var url = location.href, i = url.indexOf("?") + 3;
              MODx.loadPage(url.substr(i));
              

              On a new project utilizing a variation of the original plugin, the value of pagetitle is set based on the values of 3 tvs. Is it possible to reload the page only if there has been a change in these tvs (as opposed to a specific value)?

              Note: I'm using this plugin for modx 2.5.2.
                • 39501
                • 163 Posts