I am using Summernote 0.8.20 and am trying to populate with seed text depending on the selection of a table field (i.e., the seed text changes depending on the table cell selected). The first time I select a triggering table cell (i.e., one that meets the criteria) it works. The second time the seed text is not displayed and there is a console error:
summernote-bs4.min.js:2 Uncaught TypeError: Cannot read properties of null (reading 'appendChild')
The error is caused by the lines:
if ($.inArray(currentColumn, assistArray) > -1) {
$('#ymSpecificLine').summernote('pasteHTML', '<p><b>How were you involved in reviewing?</b><br><br></p> <p><b>How did you assist?</b><br><br></p> <p><b>How were you involved in planning?</b><br><br></p> <p><b>My role was (what did you do):</b><br><br></p>');
}else {
$('#ymSpecificLine').summernote('pasteHTML', '<p><b>How were you involved in reviewing?</b><br><br></p> <p><b>How did you lead?</b><br><br></p> <p><b>How were you involved in planning?</b><br><br></p> <p><b>My role was (what did you do):</b><br><br></p>');
}
I know this because when I comment them out the error does not occur.
The HTML:
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Assist/Lead Details</h4>
</div>
<div class="modal-body">
<!-- Summernote input area -->
<div class="row">
<div class="container-fluid">
<div id='ymSpecific' class="row">
<div class="container-fluid">
<div class="input-group">
<label for="ymSpecificLine" class="text-left col-lg-12 col-md-12 col-sm-12 col-xs-12 col-form-label">You may enter specific information relating to you Assist or Lead:</label>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 text-left">
<textarea class="summernote col-lg-12 col-md-12 col-sm-12 col-xs-12" id="ymSpecificLine" name="ymSpecificLine" rows="20"></textarea>
</div>
</div>
</div><!-- /container -->
</div><!-- /row -->
</div><!-- /container -->
</div><!-- /row -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Clear</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
The JS:
var leadArray = [8, 16, 24, 32, 44, 52, 60, 68, 80, 81, 82, 83, 91, 92, 93, 94,
102, 103, 104, 105, 113, 114, 115, 116];
var assistArray = [7, 15, 23, 31, 42, 43, 50, 51, 58, 59, 66, 67, 77, 78, 79, 88, 89, 90,
99, 100, 101, 110, 111, 112];
$("#ymSpecificLine").summernote('code', '');
var currentColumn = parseInt(sel.dataset.column, 10);
//Check if Assist or Lead (requires details to be entered)
alert("New currentColumn: " + currentColumn);
if ($.inArray(currentColumn, assistArray) > -1 || $.inArray(currentColumn, leadArray) > -1){
$('.summernote').summernote({
toolbar: [
// [groupName, [list of button]]
['style', ['bold', 'italic', 'underline', 'clear']],
['font', ['strikethrough']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']]
]
});
$("#myModal").modal('show');
if ($.inArray(currentColumn, assistArray) > -1) {
$('#ymSpecificLine').summernote('pasteHTML', '<p><b>How were you involved in reviewing?</b><br><br></p> <p><b>How did you assist?</b><br><br></p> <p><b>How were you involved in planning?</b><br><br></p> <p><b>My role was (what did you do):</b><br><br></p>');
}else {
$('#ymSpecificLine').summernote('pasteHTML', '<p><b>How were you involved in reviewing?</b><br><br></p> <p><b>How did you lead?</b><br><br></p> <p><b>How were you involved in planning?</b><br><br></p> <p><b>My role was (what did you do):</b><br><br></p>');
}
}
The result on first select:
The result on second select:

