Janusz,
Here is my implementation which is essentially the same as that I put in my post last year (Wed Jun 06, 2018 11:25 pm). It works fine and I have not heard of any problems with it. The key point is this approach does not try to convert a nuBuilder textarea object into a Trumbowyg editor object. When the form is loaded the contents of the textarea objects are copied to the separate trumbowyg objects and just before saving, the reverse occurs. There is no doubt this could be improved but it has worked well for what I needed.
1. This is the content in the setup>header (just above the final '<script>'). I have placed the trumbowyg files in a folder called 'custlibs'. You can also see that I have used a number of the plugins
Code: Select all
<link href="custlibs/trumbowyg/ui/trumbowyg.css" rel="stylesheet">
<link href="custlibs/trumbowyg/plugins/table/ui/trumbowyg.table.min.css" rel="stylesheet">
<script type="text/javascript" src="custlibs/trumbowyg/trumbowyg.min.js"></script>
<script type="text/javascript" src="custlibs/trumbowyg/plugins/table/trumbowyg.table.min.js"></script>
<script type="text/javascript" src="custlibs/trumbowyg/plugins/cleanpaste/trumbowyg.cleanpaste.min.js"></script>
<script type="text/javascript" src="custlibs/trumbowyg/plugins/fontfamily/trumbowyg.fontfamily.min.js"></script>
<script type="text/javascript" src="custlibs/trumbowyg/plugins/fontsize/trumbowyg.fontsize.min.js"></script>
<script type="text/javascript" src="custlibs/trumbowyg/plugins/pasteimage/trumbowyg.pasteimage.min.js"></script>
<script>
2. For each textarea object there needs to be a corresponding HTML object that can be converted to a trumbowyg editor. When the form is loaded with data, the HTML content from the textarea object is copied to the corresponding trumbowyg object. This is why the naming and class is important. The easiest way to do this is to create the textarea with the properties you want and then clone it. Change the Type from 'Textarea' to 'HTML' and give it a new ID (any unique ID is fine). Then go to the HTML properties of the object and enter the HTML code for the div. The code I use relies on the naming and so this is important. In this example, the textarea object that stores the rich text content is called 'defterms' and so the ID in the div must be 'tre-defterms'. Take the name of the textarea and add the 'tre-' prefix. The class must always be 'tre-editor'.
Code: Select all
<style> li {display: list-item;} </style>
<div id="tre-defterms" class="tre-editor" style="background:white;height:450px"></div>
3. This is the code that needs to go in the form's JavaScript section. I have retained all the original names of the textarea fields in my application. There are 8 in all, on different tabs. All you need to do for this to work is put the names of your textarea fields in the treField array. Obviously other changes can be made to modify the features of the editor but this will work with your application as long as the HTML objects have the correct IDs. My nuBeforeSave() has other code but I removed this to avoid confusion.
Code: Select all
var treField = ['defterms','disaggtype','calcmethod','qualitycontrol','datasources','datacollectionmethod','resultindicated','notes'];
// Convert all the elements with tre-editor class to the trumbowyg editor.
// Add a listener to run nuHasBeenEdited to monitor if any changes are made to these elements.
$(document).ready(function() { $('.tre-editor').trumbowyg({
btns: [
['viewHTML'],
['undo', 'redo'],
['formatting'],
['fontfamily'],
['fontsize'],
['strong', 'em', 'del'],
['superscript', 'subscript'],
['link'],
['insertImage'],
['pasteImage'],
['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'],
['unorderedList', 'orderedList'],
['horizontalRule'],
['table'],
['removeformat'],
['fullscreen']
],
plugins: {
table: {
rows : 12,
columns : 6
}
},
semantic: false,
resetCss: true,
removeformatPasted: true,
autogrow: true
}).on('tbwchange', function(){ nuHasBeenEdited(); });
// Load the 'tre' elements with the contents from the textarea originals.
treField.forEach(function(element) {
if ($("#"+element).val() !== undefined) {
$("#"+"tre-"+ element).trumbowyg('html', $("#"+element).val());
}
nuHide(element); // hide the textarea object
});
nuHasNotBeenEdited(); // Set the form back to 'not been edited' status.
});
// copy the contents of the 'tre' elements back to the textarea originals before saving the form
function nuBeforeSave() {
var hcont;
treField.forEach(function(element) {
hcont = $("#"+"tre-"+ element).trumbowyg('html');
$("#"+element).val(hcont).change();
});
return true;
}
I hope this helps.
Neil