Hey folks, wondering if anyone has any insight as to why a wysiwyg editor (summernote) would initialize okay on a hook mount , but doesn’t re-initialize on a hook updated event?
I could phx-update=“ignore” this, but I need to be able to re-order a list of these with liveview.
This is for liveview 15.7. The JS code is here:
Hooks.InitSummernote = {
mounted() {
init_summernote(
this.el,
this.el.dataset.target,
this.el.dataset.input,
this.el.dataset.updateEvent,
this.el.dataset.dbid,
this
);
},
updated() {
/* Todo: debounce this */
init_summernote(
this.el,
this.el.dataset.target,
this.el.dataset.input,
this.el.dataset.updateEvent,
this.el.dataset.dbid,
this
);
}
}
function init_summernote(el, targetComponent, targetInput, updateEvent, databaseID, lv) {
$(el).summernote({
minHeight: 200,
toolbar: [
['font', ['bold', 'italic', 'underline', 'clear']],
['para', ['ul', 'ol', 'paragraph']],
['view', ['codeview']]
],
tooltip: false,
cleaner: {
action: 'paste',
keepHtml: false,
},
callbacks: {
onChange: function (contents, $editable) {
$(targetInput).html(contents);
if (targetInput != undefined && updateEvent != undefined && databaseID != undefined) {
lv.pushEventTo(targetComponent, updateEvent, { content: contents, target: targetInput, id: databaseID })
}
}
}
})
console.log("init summernote")
}
And the liveview template:
<input
id="<%= @form_names_map.consent %>[<%= @repeater_index %>][content]"
name="<%= @form_names_map.consent %>[<%= @repeater_index %>][content]"
type="hidden" name="content" value="<%= @content %>">
<div class="max-w-full">
<textarea class="summernote" phx-hook="InitSummernote"
id="<%= "consents-#{@id}-content" %>"
data-dbid="<%= @id %>"
data-target="<%= @myself %>"
data-update-event="consent_change"
data-input="<%= @form_names_map.consent %>[<%= @repeater_index %>][content]">
<%= @content %>
</textarea>
</div>
Any ideas why this wouldn’t work? Or a better solution to handle a list of re-orderable wysiwyg editors while staying in sync with the liveview?