I am using SugarCRM 6.5.x CE version. I want to make a dependent functionality where I have a dropdown field with list of email template name. And according to the selection of email template, textarea should be filled with email template body text. So, I have achieved the result.
Now, instead of normal textarea, I want to show this body text in tinymce editor textarea. Now, I have "convert" my textarea into tinymce editor textarea by going through this url How to convert textarea into tinymce editor
Now, when I chose email template from dropdown field, this tinymce textarea doesn't fill up with respective body text.
This is my javascript for normal textarea, and its working
function display_text(){
if(typeof(document.getElementsByName('email_template_c')[0].value) != "undefined"){
var custom_data = document.getElementsByName('email_template_c')[0].value;
if(custom_data != ''){
$.ajax({
url:'index.php?entryPoint=check_email_template_subject',
data:{new_custom_data: custom_data},
success: function(data){
if(data!= ''){
document.getElementsByName("email_template_body_c")[0].value = data;
SUGAR.util.callOnChangeListers(document.getElementsByName("email_template_body_c")[0]);
}else{
document.getElementsByName("email_template_body_c")[0].value = '';
SUGAR.util.callOnChangeListers(document.getElementsByName("email_template_body_c")[0]);
}
}
});
}
}
}
This is my code for tinymce editor textarea which is not working
function display_text(){
if(typeof(document.getElementsByName('email_template_c')[0].value) != "undefined"){
var custom_data = document.getElementsByName('email_template_c')[0].value;
if(custom_data != ''){
$.ajax({
url:'index.php?entryPoint=check_email_template_subject',
data:{new_custom_data: custom_data},
success: function(data){
if(data!= ''){
$("p").parent(".mceContentBody").val(data);
SUGAR.util.callOnChangeListers($("p").parent(".mceContentBody").val(data));
}else{
$("p").parent(".mceContentBody").val();
SUGAR.util.callOnChangeListers($("p").parent(".mceContentBody").val());
}
}
});
}
}
}
where this ajax gets data from this check_email_template_subject.php file
<?php
global $db;
if($_REQUEST['new_custom_data'] != null){
$template_id = urldecode($_REQUEST['new_custom_data']);
$query1 = "SELECT body FROM email_templates WHERE id = '$template_id'";
$result1 = $db->query($query1);
$row1 = $db->fetchByAssoc($result1);
echo $row1['body'];
}
?>
And this is html code of tinymce editor texarea,
<html>
<head xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="X-UA-COMPATIBLE" content="IE=7">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body dir="ltr" id="tinymce" class="mceContentBody" contenteditable="true">
<p>//Here should come email template body text
<br>
</p>
</body>
</html>
Use setContent
method of active Editor in tinyMCE
suppose you have value as
var txtVal = $(".dropdown").val(); // dropdown value
//set value as in your active tinyMCE's textarea editor
tinyMCE.activeEditor.setContent(txtVal );
Hope it will work :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With