How to create tinymce dependent text area according to the choice of email template name?

I am using SugarCRM version 6.5.x CE. I want to create dependent functionality where I have a drop-down box with a list of email template names. And according to the choice of the email template, textarea should be filled with the text text of the email template. So, I have achieved the result.

Now, instead of the usual text field, I want to show this main text in the tinymce text editor. Now I am "converting" my text area to the tinymce text editor by looking at this url How to convert textarea to tinymce editor

Now that I have selected the email template from the drop down box, this tinymce text box is not populated with the corresponding body text.

This is my javascript for plain text field 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 tinymce text editor code that doesn't work

 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 does this ajax get data from this file check_email_template_subject.php

 <?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 the html code of the tinymce texarea editor,

 <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> 
+6
source share
1 answer

Use the setContent method of the active editor in tinyMCE

Suppose you have a value like

 var txtVal = $(".dropdown").val(); // dropdown value //set value as in your active tinyMCE textarea editor tinyMCE.activeEditor.setContent(txtVal ); 

Hope it works :)

+1
source

Source: https://habr.com/ru/post/982774/


All Articles