Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

pablospfc

problemas no Textarea - Tinymce

Recommended Posts

Ola, estou utilizando a biblioteca tinymce para usar html dentro de uma textearea e salvar no banco de dados Mysql. Só que estou com problemas na hora de trazer esse dado via json. Esse dado não aparece na textarea quando utilizo o tinymce, mas quando utilizo a textarea normal, sem o tinymce, ele aparece normalmente.

 

Script do Tinymce

<script type="text/javascript">
	
	tinymce.init({
		selector: "textarea#elm1",
		theme: "modern",
		plugins: [
			"advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",
			"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
			"save table contextmenu directionality emoticons template textcolor paste fullpage textcolor colorpicker"
		],
		external_plugins: {
			//"moxiemanager": "/moxiemanager-php/plugin.js"
		},
		content_css: "../views/editos/tests/manual/css/development.css",
		add_unload_trigger: false,
		autosave_ask_before_unload: false,

		toolbar1: "save newdocument fullpage | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect",
		toolbar2: "cut copy paste pastetext | searchreplace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor image media help code | insertdatetime preview | forecolor backcolor",
		toolbar3: "table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft | insertfile insertimage",
		menubar: false,
		toolbar_items_size: 'small',

		style_formats: [
			{title: 'Bold text', inline: 'b'},
			{title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
			{title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
			{title: 'Example 1', inline: 'span', classes: 'example1'},
			{title: 'Example 2', inline: 'span', classes: 'example2'},
			{title: 'Table styles'},
			{title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
		],

		templates: [
			{title: 'My template 1', description: 'Some fancy template 1', content: 'My html'},
			{title: 'My template 2', description: 'Some fancy template 2', url: 'development.html'}
		],

        spellchecker_callback: function(method, data, success) {
			if (method == "spellcheck") {
				var words = data.match(this.getWordCharPattern());
				var suggestions = {};

				for (var i = 0; i < words.length; i++) {
					suggestions[words[i]] = ["First", "second"];
				}

				success({words: suggestions, dictionary: true});
			}

			if (method == "addToDictionary") {
				success();
			}
		}
	});
</script>

Função javascript utilizada para trazer o dado via json e jogar no textarea.

<script type="text/javascript">
$(document).ready(function(){
	$("select[name='macro']").change(function(){
		var laudo = $("textarea[name='laudo']");
		
		
		$( laudo ).val('Carregando...');
		
			$.getJSON(
				'function.php',
				{ id: $( this ).val() },
				function( json )
				{
					$(laudo).val( json.macro );
					
					
				}
			);
	});
});
</script>

Código PHP utilizado para setar o dado no json

<?php
function retorna($id) {
	$id = ( int ) $id;

	require_once ("../control/CrtMacro.php");
	$obj_macro = new CrtMacro ();
	$dados = $obj_macro->buscar($id);
	$arr = Array ();

	$arr ['macro'] = $dados[0]["descricao"];
	return json_encode ( $arr );
}

if (isset ( $_GET ['id'] )) {
	echo retorna ( $_GET ['id'] );
}
?>

Textarea

<form>
<label for="laudo">:: Laudo Médico</label>
<textarea id="elm1" name="laudo" cols="125" rows="25"></textarea>
</form>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Cara pelo oque me recordo, uma vez precisei pegar informação dele e não estava conseguindo, dai fui ver que ele mudava o nome do componente, vc não manda para o TEXTAREA e sim pro componente que ele cria

Compartilhar este post


Link para o post
Compartilhar em outros sites

Até que consigo salvar dados dele em html no banco de dados, o problema está na hora de trazer o dado via Json, pois estou utilizando uma selectbox, onde seleciono uma opção e automaticamente auto-preenche na textarea do Tinymce. Já tentei com outras bibliotecas similares ao Tinymce e também não funciona. Só funciona com a textarea padrão.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Realmente não é passada para a textarea diretamente, consegui resolver fazendo assim:

<script type="text/javascript">
$(document).ready(function(){
	$("select[name='macro']").change(function(){
		var laudo = $("textarea[name='laudo']");
		
		
		$( laudo ).val('Carregando...');
		
			$.getJSON(
				'function.php',
				{ id: $( this ).val() },
				function( json )
				{
					//tinyMCE.triggerSave();
					//$(laudo).val( json.macro);
					tinymce.get('elm1').setContent(json.macro);
	
				}
			);
	});
});
</script>

Compartilhar este post


Link para o post
Compartilhar em outros sites

:D

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.