hacer readonly / deshabilitar tinymce textarea
Necesito deshabilitar o hacer de readonly un tinymce textarea en tiempo de ejecución.
10 answers
Utilice el parámetro de configuración readonly
tinyMCE.init({
...
theme : "advanced",
readonly : 1
});
Aquí hay un enlace a una demo.
Update : Lo que puede hacer para evitar que los usuarios editen contenido en su editor es establecer el atributo contenteditable del cuerpo del iframe de editores en false:
tinymce.activeEditor.getBody().setAttribute('contenteditable', false);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-12-17 08:42:30
De la versión 4.3.x on puede usar el código a continuación para el modo readonly
tinymce.activeEditor.setMode('readonly');
Y para el modo de diseño:
tinymce.activeEditor.setMode('design');
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-14 08:40:25
SI solo tiene un editor, esto funciona:
tinymce.activeEditor.getBody().setAttribute('contenteditable', false);
Si tiene varios editores, debe seleccionarlos por el id del área de texto:
tinyMCE.get('textarea_id').getBody().setAttribute('contenteditable', false);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-03-17 16:31:26
La solución de Thariama establecerá todos los TinyMCE textareas en la página como readonly.
La mejor solución que he encontrado fue publicado por Magnar Myrtveit que establecerá los campos a readonly que tienen el atributo readonly. Aquí está el código:
tinyMCE.init({
...
setup: function(ed) {
if ($('#'+ed.id).prop('readonly')) {
ed.settings.readonly = true;
}
}
});
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:18:14
Para desactivar puede llamar a este comando:
tinymce.EditorManager.execCommand('mceToggleEditor', true, tinymceId);
Y para activar de nuevo el editor, puede volver a llamar a este comando.
'El comando mceToggleEditor activa o desactiva el modo WYSIWYG mostrando u ocultando la instancia textarea y editor. Esto no es lo mismo que mceAddControl o mceRemoveControl porque la instancia todavía está allí y no está inicializada, por lo que este método es más rápido.
Enlace para el comando anterior: http://archive.tinymce.com/wiki.php/TinyMCE3x:Command_identifiers
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-13 12:55:37
Puede usar
this.getBody().setAttribute('contenteditable', false);
Echa un vistazo a la solución completa,, mi lado del servidor es Asp.net MVC
setup: function (ed) {
ed.on('init', function () {
this.execCommand("fontSize", false, "17px");
$("html,body").scrollTop(0);
@if (ViewBag.desableEdit != null && ViewBag.desableEdit == true)
{
<text>
this.getBody().setAttribute('contenteditable', false);
</text>
}
});
Otra forma de hacerlo si tiene server side condition
que se eliminará en el HTML devuelto
tinymce.init({
selector: ... ,
....
@if (ViewBag.desableEditExseptExportNumber != null && ViewBag.desableEditExseptExportNumber == true)
{
<text>
readonly: 1,
</text>
}
language: 'ar',
....});
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-10-19 16:59:28
Tal vez esta línea de código ayude en otros navegadores que usan iframes.
tinymce.activeEditor.getBody().contenteditable = false
Saludos!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-04 06:23:11
Trato de usar solo lectura: 1 comando cuando lo uso la barra de herramientas desaparece.
Cómo usar el
Tinymce.Activador.getBody().setAttribute ('contenteditable', false);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-17 05:17:25
Usted puede ver esta respuesta aquí por @amotinaron: https://stackoverflow.com/a/34764607/1827960.
Lo usé para llegar a esta solución:
tinymce.settings = $.extend(tinymce.settings, { readonly: 1 });
tinymce.EditorManager.editors.forEach(function (editor) {
tinymce.EditorManager.execCommand('mceRemoveEditor', false, editor.id);
//tinymce.EditorManager.editors = [];
tinymce.EditorManager.execCommand('mceAddEditor', false, editor.id);
});
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:18:14
Que funciona para ASP.NET MVC Razor
readonly: @(Model.Readonly ? "true" : "false")
Al inicializar TinyMCE:
tinymce.init({/* put readonly setting here */});
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-03 16:40:19