so, ideally the values of this TVs would be syncronized as you type the pagetitle and they shouldn't be editable with custom values?
-
☆ A M B ☆
- 24,524 Posts
Now, that's just going too far
-
☆ 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.
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
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>