We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Try changing the constraint field to "id" if you only want it to apply to certain documents. smiley
      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
      • 31912 MODX Staff
      • 95 Posts
      Thanks for the response – it didn’t seem to fixit :/ I am able to rename/hide fields on a per-template basis using the constraint field of "template" and putting the id of the template in the constraint field.
        • 31912 MODX Staff
        • 95 Posts
        I think it might work using the name of the template rather than the ID of the template in the value box... not sure why I didn’t try that before.

        edit: never mind, I spoke too soon, doing this changes the default template for the entire site not just based on what would otherwise be the inherited template.
          • 3749
          • 24,544 Posts
          Quote from: waldus68 at Jun 21, 2010, 09:19 PM

          Thanks for the response – it didn’t seem to fixit :/ I am able to rename/hide fields on a per-template basis using the constraint field of "template" and putting the id of the template in the constraint field.

          That’s expected, if you’re modifying the Create/Edit Resource panel, the constraint field will always refer to a field of the current document. So you’re telling it to only execute if the document’s "template" field is set to a particular template’s ID.

          But now I’m confused about what you’re trying to do. You said in your original post that you wanted to set the template of a template. I assumed that you meant the template of a document since templates don’t have templates.



            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
            • 31912 MODX Staff
            • 95 Posts
            Thanks again for the help.

            Your right, I am referring to the template field of documents. What I am trying to do is set the default template of a resource (on create) with a particular template to a template that is intended for child documents. I have a series of documents functioning as Project Folders that contain the primary information about a project. Each project document will have a varying amount of child documents that are related to that project and would be ideal to use a separate template with a different set of template variables. Very similar to the functionality of Inherit Selected Template plugin for evo.

            Project
            |-Project Child
            |-Project Child

            I have form customization working great for changing or hiding fields based on the resource’s template and thought I could achieve the same thing by modifying the default value of the template field of that parent template to the template that I want the child documents to use.

            I am able to change the template using the method I had a screen capture and your suggestion, but this is for the entire site and not just for creating a document under a document with a particular template. So if I create a document under about us using a generic template it still changes the template field value to what I set in the rule, although other rules like renaming pagetitle for (using the same setup in the constraints field) work as expected.

            There is a very good chance I am just trying to do something that form customization isn’t meant to do and everything is functioning as it should.
              • 3749
              • 24,544 Posts
              I think the problem is that the Form Customization rule doesn’t have access to the template value of the parent.

              It should be relatively easy to create a plugin listening to OnDocFormPrerender, but I think it will only work on update, not create, because the $resource variable isn’t available for new docs until after the Create/Edit Resource form has been rendered ( I could be wrong).

              Something like this:

              $parent = $resource->get(parent');
              
              if ($parent) {
                  $parentObj = $resource->getOne('Parent');
                  $resource->set('template', $parentObj->get('template'));
              }
                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
                • 3151
                • 7 Posts
                Hi all,

                Just came across a problem when setting up some rules in this Form Customization.

                Here’s one of my settings:

                Action: core - resource/create (51)

                Field: class_key
                Containing Panel: modx-page-settings
                Rule: Field Visible
                Value: 0

                Constraint Class: modDocument (this really is optional but - I want to apply it just to modDocument class)

                all that seems producing this code in the manager screen when I go to this url: http://[site-name]/manager/?a=51

                <script type="text/javascript">Ext.onReady(function() {Ext.getCmp("modx-page-settings").hideField("class_key");});</script>
                


                but there is a javascript error when loading the page - and the field is not hidden, here’s the error:


                Ext.getCmp("modx-page-settings").hideField is not a function
                <script type="text/javascript">Ext.onR....hideField("class_key");});</script>

                manager?a=51 (line 66)

                I’m not too familiar with Ext JS library - but I think this because the function is not defined inside the Ext object which makes the function call - and when I looked at modext js - I see that there are two (2) instances of hideField function defined inside MODx.Window & MODx.FormPanel (as an extension of Ext.Window & Ext.FormPanel repectively)

                Ext.extend(MODx.Window, Ext.Window, {
                
                ...
                
                    hideField: function (B) {
                        if (!Ext.isArray(B)) {
                            B = B[B];
                        }
                        var C;
                        for (var A = 0; A < B.length; A++) {
                            C = this.getField(B[A]);
                            if (!C) {
                                return;
                            }
                            C.hide();
                            var D = C.getEl().up(".x-form-item");
                            if (D) {
                                D.setDisplayed(false);
                            }
                        }
                    },
                
                ...
                
                }
                


                I tried:

                MODx.Window.getCmp("modx-page-settings").hideField("class_key");
                
                and
                
                MODx.FormPanel.getCmp("modx-page-settings").hideField("class_key");
                


                but both failed - getCmp does not exist in those two objects. Is there any workaround for this ? or this is because MODx extension objects has not call it’s superclasses ? - I’m just guessing, here huh

                I experience this problem under MODx Revolution 2.0.0-rc-2 rev6923 & MODx Revolution 2.0.0-pl rev7212

                I really appreciate it, if there is anyone here could give me any suggestions/workaround. Thanks
                  • 21257 MODX Staff
                  • 730 Posts
                  I thought that this would be a good opportunity to acquaint myself with form customization.

                  Here’s what I found.
                  Setting "containing panel" to "modx-panel-resource" gives us a modx.panel object with the hideField method.
                  However, the rule still wasn’t working for me, so I traced the javascript code and came up with the following workaround:

                  manager/assets/modext/widgets/core/modx.panel.js
                  line 204:
                  if (!Ext.isArray(flds)) { flds = [flds]; }
                  

                  apply the same workaround to line 216.

                  The previous code was causing the value of flds to become undefined. (At least in my version of Firefox.)
                  This is not a patch or proper fix, but it did get the rule working for me.
                    Mike Schell
                    Lead Developer, MODX Cloud
                    Email: [email protected]
                    GitHub: https://github.com/netProphET/
                    Twitter: @mkschell
                    • 21257 MODX Staff
                    • 730 Posts
                    Just realized, if your javascript is minimized, it will be trickier to apply that workaround... undecided
                      Mike Schell
                      Lead Developer, MODX Cloud
                      Email: [email protected]
                      GitHub: https://github.com/netProphET/
                      Twitter: @mkschell
                      • 3151
                      • 7 Posts
                      Hi,

                      I actually managed to find out what seems to be the problem:

                      It turns out the problem is not because the function is not defined properly inside the object, but its because "modx-page-settings" tab does not exist.

                      There seems to be a "modx-resource-page-settings" defined in one of the javascript, but the fields (that I was targeting) actually live inside "modx-panel-resource" (even they are in page settings tab, and the documentation point out "modx-page-settings" value for this setting - http://svn.modxcms.com/docs/display/revolution/FC-Resource#FC-Resource-ResourceCreate%2FUpdate ) - so I don’t really know if this is a bug/or a revision to the previous code.

                      But when I changed my settings to:
                      Action: core - resource/create (51)

                      Field: class_key
                      Containing Panel: modx-panel-resource
                      Rule: Field Visible
                      Value: 0

                      It now then creates this code:
                      Ext.onReady(function() {Ext.getCmp("modx-panel-resource").hideField("class_key");});
                      


                      which works!! thanks for looking into my problem..