Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/templates/_formfields/multi-line-text/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{% block field %}
{% if field.useRichText %}
<div class="fui-rich-text" data-rich-text></div>
<div class="fui-rich-text" data-rich-text {% if field.placeholder %} data-placeholder="{{ field.placeholder}}" {% endif %}></div>

<div style="display: none !important;">
{% include '_includes/forms/textarea' with { rows: 5 } %}
Expand Down
14 changes: 12 additions & 2 deletions src/web/assets/frontend/src/js/fields/rich-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class FormieRichText {
this.$field = settings.$field.querySelector('textarea');
this.$container = settings.$field.querySelector('[data-rich-text]');
this.scriptId = 'FORMIE_FONT_AWESOME_SCRIPT';
this.defaultParagraphSeparator = 'p';

this.buttons = settings.buttons;

Expand Down Expand Up @@ -143,11 +144,17 @@ export class FormieRichText {

const options = {
element: this.$container,
defaultParagraphSeparator: 'p',
defaultParagraphSeparator: this.defaultParagraphSeparator,
styleWithCSS: true,
actions: this.getButtons(),
onChange: (html) => {
this.$field.textContent = html;
// catch "empty" HTML if we're using a placeholder
if (this.$field.placeholder && html === `<${this.defaultParagraphSeparator}><br></${this.defaultParagraphSeparator}>`) {
this.$field.textContent = "";
this.editor.content.innerHTML = "";
} else {
this.$field.textContent = html;
}

// Fire a custom event on the input
this.$field.dispatchEvent(new CustomEvent('populate', { bubbles: true }));
Expand All @@ -171,6 +178,9 @@ export class FormieRichText {

this.$field.dispatchEvent(beforeInitEvent);

// save the defaultParagraphSeparator again, if it changed
this.defaultParagraphSeparator = options.defaultParagraphSeparator || this.defaultParagraphSeparator;

this.editor = init(options);

// Populate any values initially set
Expand Down
5 changes: 5 additions & 0 deletions src/web/assets/frontend/src/scss/fields/_rich-text.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,8 @@
}
}

// Add placeholder
.fui-rich-text-content[data-placeholder]:empty::before {
content: attr(data-placeholder);
}