Skip to content

Instantly share code, notes, and snippets.

@miteshmap
Created December 19, 2014 20:50
Show Gist options
  • Select an option

  • Save miteshmap/be86f9324336da8efaf2 to your computer and use it in GitHub Desktop.

Select an option

Save miteshmap/be86f9324336da8efaf2 to your computer and use it in GitHub Desktop.
Drupal - write value to textarea with editor with js
(function ($) {
Drupal.fooModule = Drupal.enrich || {};
Drupal.fooModule.copyToTextarea = function($field, $value, settings) {
for (var editor in settings.wysiwyg.configs) break;
$("textarea[name^='"+ $field +"']").val($.trim($value));
var editorid = $("textarea[name^='"+ $field +"'].text-full").attr('id');
if (typeof editorid != 'undefined' && editorid.length > 0) {
if (editor == 'tinymce') {
tinyMCE.execInstanceCommand(editorid, 'mceSetContent', false, $.trim(html));
}
else if (editor == 'ckeditor') {
CKEDITOR.instances[editorid].setData($.trim(html));
}
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment