{"id":3648,"date":"2016-07-27T15:00:29","date_gmt":"2016-07-27T11:00:29","guid":{"rendered":"http:\/\/dhtmlx.com\/blog\/?p=3648"},"modified":"2026-04-03T15:33:26","modified_gmt":"2026-04-03T12:33:26","slug":"custom-item-dhtmlxform-example-ckeditor-integration","status":"publish","type":"post","link":"https:\/\/dhtmlx.com\/blog\/custom-item-dhtmlxform-example-ckeditor-integration\/","title":{"rendered":"Custom Item in dhtmlxForm by the Example of CKEditor Integration"},"content":{"rendered":"<p>\n        <div class=\"info-block\">\n            <div class=\"info-icon\">\n                <svg viewBox=\"0 0 14 16\">\n                    <path fill-rule=\"evenodd\" d=\"M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z\"><\/path>\n                <\/svg>\n\n                INFO\n            <\/div>\n\n            <div class=\"info-content\">\n                <p>\n                    If you are using an outdated version of DHTMLX Suite 5 and require the documentation for it, \n                    please <a href=\"https:\/\/dhtmlx.com\/docs\/contact.shtml\" title=\"\">contact us<\/a>, <br \/>and we will send it to you.\n                <\/p>\n            <\/div>\n        <\/div>\n    <br \/>\n<strong>Update: Now DHTMLX has its own <a href=\"https:\/\/dhtmlx.com\/docs\/products\/dhtmlxRichText\/\" rel=\"noopener\" target=\"_blank\">WYSIWYG editor &#8211; Rich Text Editor<\/a> launched in December 2018.<\/strong><\/p>\n<p>Using of DHTMLX UI components goes beyond the standard functionality described in docs. We&#8217;d like to share a simple way of adding a custom item in dhtmlxForm control. For more informative demonstration, we&#8217;ll integrate <a href=\"https:\/\/ckeditor.com\/\">CKEditor<\/a>, a popular WYSIWYG Editor, with our <a href=\"https:\/\/dhtmlx.com\/docs\/products\/dhtmlxForm\/\">Form<\/a>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2016\/07\/CKEditor-with-dhtmlx.png\" alt=\"CKEditor with dhtmlx\" width=\"657\" height=\"558\" class=\"aligncenter size-full wp-image-3653\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2016\/07\/CKEditor-with-dhtmlx.png 657w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2016\/07\/CKEditor-with-dhtmlx-300x255.png 300w\" sizes=\"auto, (max-width: 657px) 100vw, 657px\" \/><\/p>\n<p>Each item requires a number of basic functions that are called depending on operations, in particular:<\/p>\n<p><strong>&#8211; render<\/strong> is an initial item rendering method that is called 1 time. You can also specify any configuration settings here.<\/p>\n<p><strong>&#8211; setValue<\/strong> is an internal method that sets up the value to an item at myForm.setFormData() and myForm.setItemValue() commands.<\/p>\n<p><strong>&#8211; getValue<\/strong> returns the value of the item and is called at form\u2019s commands myForm.getItemValue() and myForm.getFormData()<\/p>\n<p>&#8211; additionally we need getFormData_[itemname] and getFormData_[itemname] wrappers for set\/getFormData<\/p>\n<p>Now we move on to the CKEditor settings:<br \/>\n<em><br \/>\nrender<\/em> &#8211; here we create a usual text area and call init of the CKEditor itself. Then we need to pass the parameters from formData to it, i.e.:<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\">CKEDITOR.<span class=\"me1\">replace<\/span><span class=\"br0\">&#40;<\/span>item._ckId<span class=\"sy0\">,<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; width<span class=\"sy0\">:<\/span> data.<span class=\"me1\">inputWidth<\/span><span class=\"sy0\">||<\/span><span class=\"st0\">&quot;auto&quot;<\/span><span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; &nbsp; height<span class=\"sy0\">:<\/span> data.<span class=\"me1\">inputHeight<\/span><span class=\"sy0\">||<\/span><span class=\"st0\">&quot;auto&quot;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>In addition, we will add an event for CKEditor. It will call the onChange event of the form when the value in the editor will be changed. The onChange event will fire when the user will finish editing and move the mouse pointer out of the input.<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\">CKEDITOR.<span class=\"me1\">instances<\/span><span class=\"br0\">&#91;<\/span>item._ckId<span class=\"br0\">&#93;<\/span>.<span class=\"me1\">on<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;blur&quot;<\/span><span class=\"sy0\">,<\/span> <span class=\"kw1\">function<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"kw1\">var<\/span> v <span class=\"sy0\">=<\/span> CKEDITOR.<span class=\"me1\">instances<\/span><span class=\"br0\">&#91;<\/span>item._ckId<span class=\"br0\">&#93;<\/span>.<span class=\"me1\">getData<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span><span class=\"sy0\">!<\/span>item._unloading <span class=\"sy0\">&amp;&amp;<\/span> v <span class=\"sy0\">!=<\/span> item._value<span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; item._value <span class=\"sy0\">=<\/span> v<span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; item.<span class=\"me1\">getForm<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span>.<span class=\"me1\">callEvent<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;onChange&quot;<\/span><span class=\"sy0\">,<\/span> <span class=\"br0\">&#91;<\/span>item._idd<span class=\"sy0\">,<\/span> item._value<span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>To implement the possibility of working with several editors at once, we have added the item._ckId attribute and assigned a unique value to it.<\/p>\n<p>To set values in the editor, we use the following code:<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\">CKEDITOR.<span class=\"me1\">instances<\/span><span class=\"br0\">&#91;<\/span>item._ckId<span class=\"br0\">&#93;<\/span>.<span class=\"me1\">setData<\/span><span class=\"br0\">&#40;<\/span>...<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>In order to get the values, the code below is used:<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\">CKEDITOR.<span class=\"me1\">instances<\/span><span class=\"br0\">&#91;<\/span>item._ckId<span class=\"br0\">&#93;<\/span>.<span class=\"me1\">getData<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>To unload the editors, use the code as follows:<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\">CKEDITOR.<span class=\"me1\">instances<\/span><span class=\"br0\">&#91;<\/span>item._ckId<span class=\"br0\">&#93;<\/span>.<span class=\"me1\">destroy<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>To set focus, apply the following method:<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\">CKEDITOR.<span class=\"me1\">document<\/span>.<span class=\"me1\">getById<\/span><span class=\"br0\">&#40;<\/span>item._ckId<span class=\"br0\">&#41;<\/span>.<span class=\"me1\">focus<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>All other functions will be inherited from the standard input type.<\/p>\n<p>Thank you for reading our mini-tutorial! We hope that the given instructions were useful for you. Feel free to write your questions and comments below or in the <a href=\"https:\/\/forum.dhtmlx.com\/t\/integration-with-ckeditor\/35980\">forum topic<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update: Now DHTMLX has its own WYSIWYG editor &#8211; Rich Text Editor launched in December 2018. Using of DHTMLX UI components goes beyond the standard functionality described in docs. &#8230;<\/p>\n","protected":false},"author":2,"featured_media":3649,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,71,1,38],"tags":[33,43,31,14,10],"class_list":["post-3648","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-posts-for-codeproject-com","category-tutorials","category-uncategorized","category-visible","tag-all-posts","tag-dhtmlx-tips","tag-form","tag-tips","tag-dhtmlxsuite"],"_links":{"self":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/3648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/comments?post=3648"}],"version-history":[{"count":3,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/3648\/revisions"}],"predecessor-version":[{"id":15355,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/3648\/revisions\/15355"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media\/3649"}],"wp:attachment":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media?parent=3648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/categories?post=3648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/tags?post=3648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}