Closed labr1005 closed 7 years ago
I think you could do what you want with restrictive condition for the fields. Hide normal fields on specific condions and show a read-only version of the field. Means, you have to create two versions of each field and show only the one or the other, depending on the result of the condition-snippet. It should return 1 to hide the field and an empty string to show the field.
So you're saying that it is already possible to declare a field as readonly? How?
this depends on the TV-type. About which types are you talking about?
Text and Textarea.
Ext has a readOnly - option for textBox and textArea http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.form.TextArea-cfg-readOnly but its not used within the TV - input types.
So you have to create a copy of both TV - input - types and add the option ,readOnly : true
For textarea copy this files https://github.com/modxcms/revolution/blob/2.x/core/model/modx/processors/element/tv/renders/mgr/input/textarea.class.php https://github.com/modxcms/revolution/blob/2.x/manager/templates/default/element/tv/renders/input/textarea.tpl
Custom input types... Why didn't I have this idea... Thanks!
core/model/modx/processors/element/tv/renders/mgr/input/text-readonly.class.php
<?php
/**
* @package modx
* @subpackage processors.element.tv.renders.mgr.input
*/
class modTemplateVarInputRenderTextReadonly extends modTemplateVarInputRender {
public function getTemplate() {
return 'element/tv/renders/input/textbox-readonly.tpl';
}
}
return 'modTemplateVarInputRenderTextReadonly';
manager/templates/default/element/tv/renders/input/textbox-readonly.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'
,readOnly: true
,focusClass: ''
,applyTo: 'tv{$tv->id}'
,width: '99%'
,msgTarget: 'under'
{literal}
});
Ext.getCmp('modx-panel-resource').getForm().add(fld);
MODx.makeDroppable(fld);
});
{/literal}
// ]]>
</script>
core/model/modx/processors/element/tv/renders/mgr/input/textarea-readonly.class.php
<?php
/**
* @package modx
* @subpackage processors.element.tv.renders.mgr.input
*/
class modTemplateVarInputRenderTextAreaReadonly extends modTemplateVarInputRender {
public function getTemplate() {
return 'element/tv/renders/input/textarea-readonly.tpl';
}
}
return 'modTemplateVarInputRenderTextAreaReadonly';
manager/templates/default/element/tv/renders/input/textarea-readonly.tpl
<textarea id="tv{$tv->id}" name="tv{$tv->id}" rows="15">{$tv->get('value')|escape}</textarea>
<script type="text/javascript">
// <![CDATA[
{literal}
Ext.onReady(function() {
var fld = MODx.load({
{/literal}
xtype: 'textarea'
,readOnly : true
,focusClass: ''
,applyTo: 'tv{$tv->id}'
,value: '{$tv->get('value')|escape:'javascript'}'
,height: 140
,width: '99%'
{literal}
});
MODx.makeDroppable(fld);
Ext.getCmp('modx-panel-resource').getForm().add(fld);
});
{/literal}
// ]]>
</script>
In your migx config set "Input TV type" to "text-readonly" or "textarea-readonly".
I would call this a "quick and dirty" way, but it works for me. The "proper" way to create custom input types can be found here: https://docs.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/adding-a-custom-tv-type-modx-2.2
Thanks!
In some cases I want the editor to not be able to edit a special (or all fields) in the update window - in my case it's a MIGXdb grid and update window.
So I wish there was a checkbox or another way to set the input to readonly.
(I see there's a unique id for the update window ("modx-window-mi-grid-update-MyClass") - so another option would be to do this in a plugin an listen to the event the window fires when it opens and set the readonly attributes via javascript. I just don't know which event to listen to...)