We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26903
    • 1,336 Posts
    Ok splittingred the above code is fine.

    What’s the best way to return error strings back to the form?

    I want to say things like ’no template supplied’, ’no doc id’s’ supplied’ etc. if parameter validation fails. I can sort of do this using the $this->modx->toJSON call, setting ’success’ to 0 and an appropriate message in ’message’. I get the message box OK with the message but the box label says ’Success!’ which I don’t want. Also when you OK the box it vanishes but the manager screen doesn’t refresh, I have to F5 it to get any focus back.

    I’m probably missing something here that’s easier than this.
      Use MODx, or the cat gets it!
      • 28215
      • 4,149 Posts
      Quote from: shamblett at Jan 27, 2009, 03:47 AM

      Ok splittingred the above code is fine.

      What’s the best way to return error strings back to the form?

      I want to say things like ’no template supplied’, ’no doc id’s’ supplied’ etc. if parameter validation fails. I can sort of do this using the $this->modx->toJSON call, setting ’success’ to 0 and an appropriate message in ’message’. I get the message box OK with the message but the box label says ’Success!’ which I don’t want. Also when you OK the box it vanishes but the manager screen doesn’t refresh, I have to F5 it to get any focus back.

      I’m probably missing something here that’s easier than this.

      Take a look at the MODx processors for examples, but you’ll use the error class. You’ll need to load it, if you haven’t, though, in your connector/processor loading code. So, for a success message:

      return $modx->error->success();


      And an error:

      return $modx->error->failure('Message here.');


      failure and success also take a 2nd parameter, which can be either an array, string, or xPDOObject (ie, a db object). This returns in MODx.FormPanel as o.result.object (described below).

      In the MODx.FormPanel class (assuming your forms have been extending this), it automatically handles the error/response class by firing an event, either ’success’ or ’failure’. By default, this will proceed if a success, and popup an error window (without proceeding in the form) if there’s a failure.

      If you want to add customized error handling, you’ll add listeners to your JS class that extends MODx.FormPanel. Those events are, ’failure’ and ’success’, and come passed with one parameter, which is a object of parameters. An example is this:

      /*
       * the param 'o' contains 4 keys:
       * - o.form: the FormPanel object
       * - o.result: the result object, which has o.result.message and o.result.object
       * - o.options: the options passed to the FormPanel.submit function
       * - o.config: The config passed to the FormPanel
       */
      
      // this listeners param would go in your class's config, the class that extends MODx.FormPanel
      listeners: {
      	'success': {fn:function(o) {
      		var r = o.result;
      		// let's update the page title on success
      		Ext.get('header').update('<h2>'+r.object.pagetitle+'</h2>');
      	},scope:this}
      	,'failure': {fn:function(o) {
      		// you dont need this listener unless you want to override the default behavior
      		
      		this.errorMsg = o.result.message; // like so, for some odd reason
      		
      		return true; // returning false will prevent the popup error message
      	},scope:this}
      }
      
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 26903
        • 1,336 Posts
        Excellent, thought you guys would have thought of this, I’ve already added a MODx.msg.box call in my js success function, and one for the failure listener that I’ve added, I just needed to give the user better feedback about what exactly happened.

        Ok, except for these error messages I can now select a template, a range of docs a la evo’s docmanager and apply the change, this works OK so the change template docmanager function is nearly done, phew! Hopefully now I can press on with the other functions without so much of a learning curve and get this done and packaged in the next few weeks.
          Use MODx, or the cat gets it!
          • 28215
          • 4,149 Posts
          Quote from: shamblett at Jan 27, 2009, 12:52 PM

          Excellent, thought you guys would have thought of this, I’ve already added a MODx.msg.box call in my js success function, and one for the failure listener that I’ve added, I just needed to give the user better feedback about what exactly happened.
          You actually shouldn’t need one for the failure function - you only need a failure listener if you want to do something more than display an error message.
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 26903
            • 1,336 Posts
            Yes, I just wanted to be consistent, it says something like ’Your change template request failed’ which is a bit more personalized for the form. I realize(I think) that this will only be raised if something goes wrong with the actual mechanics of the call, rather than me returning an error for a specific condition I detect e.g ’no template selected’ etc.
              Use MODx, or the cat gets it!
              • 26903
              • 1,336 Posts
              Ok guys, as part of the doc manager conversion I use this function from the main modx class, getChildIds. This has the following line :-
              if (isset ($this->resourceMap["{$id}"]))
              .

              This variable is never set hence the call returns no children.

              A brief look seems to suggest that this is context dependent, it is set in function _initContext. OK, the context I’m in when I press the ’change’ button is the docmanager context, which doesn’t have a resourceMap, so how do I generate one? What is it for? What have I missed?
                Use MODx, or the cat gets it!
                • 22303 MODX Staff
                • 10,725 Posts
                Doc manager should not be in a separate front-end context, shouldn’t that be part of the mgr context? It should manage resources and elements in the front-end contexts.
                  • 26903
                  • 1,336 Posts
                  Good point but it has a context file path and URL that points to /assets/components/docmanager etc. If I used mgr I’d have to put its files in the manager directory hierarchy would I not. I did it this way to follow the docs here http://svn.modxcms.com/docs/display/~splittingred/2008/07/10/Creating+Custom+Manager+Pages+for+a+3rd+Party+Component%2C+Pt.+I, which does say create a new context for your pages.
                    Use MODx, or the cat gets it!
                    • 22303 MODX Staff
                    • 10,725 Posts
                    Quote from: shamblett at Feb 03, 2009, 09:19 AM

                    Good point but it has a context file path and URL that points to /assets/components/docmanager etc. If I used mgr I’d have to put its files in the manager directory hierarchy would I not. I did it this way to follow the docs here http://svn.modxcms.com/docs/display/~splittingred/2008/07/10/Creating+Custom+Manager+Pages+for+a+3rd+Party+Component%2C+Pt.+I, which does say create a new context for your pages.
                    If you are extending the mgr, then it would go in the mgr context, or it could go in a custom context I suppose, but regardless of that point, it’s not going to be used to manage itself. You need to point it at data for specific contexts (like the web context) that contain Resources so it can load that context’s data to work with.
                      • 28215
                      • 4,149 Posts
                      We’re going to try and iron out the custom manager pages process. Currently it’s a bit convoluted and not optimal, tbh.
                        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com