Skip to content

Commit

Permalink
fix(textarea): on change event broken
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Jul 26, 2022
1 parent 6685b94 commit 9fb70ed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 3 additions & 2 deletions inc/field/fieldsfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,10 @@ public function prepareHtmlField($fieldName, $canedit = true, $value = '') {
'rows' => 4,
'display' => false,
]);
$html .= Html::scriptBlock("$(function() {
// This JS function intercepts tinyMCE creation then must be executed before end of page load
$html .= Html::scriptBlock("
pluginFormcreatorInitializeTextarea('$fieldName', '$rand');
});");
");
} else {
$html.= nl2br($value);
}
Expand Down
1 change: 1 addition & 0 deletions inc/field/textareafield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function getRenderedHtml($domain, $canEdit = true): string {
'multiple' => true,
'display' => false]);
$html .= '</div>';
// This JS function intercepts tinyMCE creation then must be executed before end of page load
$html .= Html::scriptBlock("$(function() {
pluginFormcreatorInitializeTextarea('$fieldName', '$rand');
});");
Expand Down
19 changes: 15 additions & 4 deletions js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1719,10 +1719,21 @@ function pluginFormcreatorInitializeTag(fieldName, rand) {
* Initialize a textarea field
*/
function pluginFormcreatorInitializeTextarea(fieldName, rand) {
var field = $('[name="' + fieldName + '"]');
field.on("change", function(e) {
plugin_formcreator.showFields($(field[0].form));
});
var i = 0;
var e;
while (e = tinymce.get(i++)) {
var field = $('[name="' + fieldName + '"]');
var form = field[0].form;
if (e.formElement != form) {
continue;
}
// https://stackoverflow.com/a/63342064
e.on('input NodeChange', function(e) {
tinyMCE.triggerSave();
plugin_formcreator.showFields($(form));
});
return;
}
}

/**
Expand Down

0 comments on commit 9fb70ed

Please sign in to comment.