We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4172
    • 5,888 Posts
    so, ideally the values of this TVs would be syncronized as you type the pagetitle and they shouldn't be editable with custom values?
      -------------------------------

      you can buy me a beer, if you like MIGX

      http://webcmsolutions.de/migx.html

      Thanks!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Now, that's just going too far wink
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 37042
        • 384 Posts
        bruno - in an ideal world, yes smiley
        The non editability is a good idea but is probably even more complicated. I could live without that.
          ...
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You could use a plugin that loads some javascript to automatically synchronize the TV fields as you edit the pagetitle. Very much like the javascript that modifies the header of the editing form as you edit the pagetitle. And setting TVs to be read-only shouldn't be a problem; the "lock variable for editing" should lock out anybody except "sudo" admin users. I think the same javascript that updates the TV value can set the field to be read-only as well.

          The javascript would be pretty specific, as you would need to know exactly the IDs or names of the fields involved so they can be automatically updated. Firebug will be useful here.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 4172
            • 5,888 Posts
            shouldn't be difficult to create a custom-TV-input-type with something like that in it:

            Ext.get('x-form-el-modx-resource-pagetitle').on('keyup', function(e, el){
                var value = Ext.get(el).getValue();
                console.log(value);
            });
            


            you can try it out by running that code in the firebug-console
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 37042
              • 384 Posts
              Quote from: Bruno17 at Apr 30, 2014, 03:35 AM
              shouldn't be difficult to create a custom-TV-input-type with something like that in it:

              Ext.get('x-form-el-modx-resource-pagetitle').on('keyup', function(e, el){
                  var value = Ext.get(el).getValue();
                  console.log(value);
              });
              



              Thanks for the pointer. It's way above my skill levels but roughly, how would the custom TV input manifest in Manager?
              Would I first create a new TV input (lets pretend its called "Mirror" by folliwng these instructions
              http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/adding-a-custom-tv-input-type

              Then create a few TVs and choose "Mirror" as the Input Options > Input Type

              ?
                ...
                • 4172
                • 5,888 Posts
                in its simplest form you would create a copy of the text-tv with this code

                mirror.class.php
                <?php
                /**
                 * @package modx
                 * @subpackage processors.element.tv.renders.mgr.input
                 */
                class modTemplateVarInputRenderMirror extends modTemplateVarInputRender {
                    public function getTemplate() {
                        return 'element/tv/renders/input/mirror.tpl';
                    }
                }
                return 'modTemplateVarInputRenderMirror';


                mirror.tpl
                <input id="tv{$tv->id}" name="tv{$tv->id}"
                	type="text" class="textfield"
                	value="{$tv->get('value')|escape}"
                	{$style}
                	tvtype="{$tv->type}"
                />
                
                <script type="text/javascript">
                // <![CDATA[
                {literal}
                Ext.onReady(function() {
                    var fld = MODx.load({
                    {/literal}
                        xtype: 'textfield'
                        ,id: 'tv{$tv->id}_cmp'
                        ,applyTo: 'tv{$tv->id}'
                        ,width: '99%'
                        ,enableKeyEvents: true
                        ,msgTarget: 'under'
                        ,allowBlank: {if $params.allowBlank == 1 || $params.allowBlank == 'true'}true{else}false{/if}
                        {if $params.maxLength},maxLength: {$params.maxLength}{/if}
                        {if $params.minLength},minLength: {$params.minLength}{/if}
                    {literal}
                        ,listeners: { 'keydown': { fn:MODx.fireResourceFormChange, scope:this}}
                    });
                    Ext.getCmp('modx-panel-resource').getForm().add(fld);
                    MODx.makeDroppable(fld);
                    
                Ext.get('x-form-el-modx-resource-pagetitle').on('keyup', function(e, el){
                    var value = Ext.get(el).getValue();
                    Ext.getCmp('{/literal}tv{$tv->id}_cmp{literal}').setValue(value);
                });    
                    
                });
                {/literal}
                // ]]>
                </script>
                

                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!