tedjimenezm
tedjimenezm
FFilament
Created by tedjimenezm on 10/25/2023 in #❓┊help
I'm migrating a big app. How can I append data to the RichEditor?
Using a custom component (livewire + alpine) with the same editor (Trix) I was able to do something like this: 1 - Click a button.
<button type="button" @click="copyTag('sometag}')">label</button>
<button type="button" @click="copyTag('sometag}')">label</button>
2 - Send an event to Trix
window.copyTag = (tag) => {
let event = new CustomEvent('editor:append', { detail: ' ' + tag });
document.dispatchEvent(event);
};
window.copyTag = (tag) => {
let event = new CustomEvent('editor:append', { detail: ' ' + tag });
document.dispatchEvent(event);
};
3 - Handle the event
<div x-on:editor:append.document="editor.commands.insertContent(event.detail);editor.commands.focus()">
</div>
<div x-on:editor:append.document="editor.commands.insertContent(event.detail);editor.commands.focus()">
</div>
I can do something like this with filament v3) using a custom field and some macro but the editor's cursor is jumping to the beginning instead of the end of the line or text.
VariablesSelector::macro('appendToContent', function () {
$this
->live(onBlur: true)
->afterStateUpdated(function (string $operation, $state, Set $set, Get $get) {
$set('content', $get('content') . ' ' . ExcerptVariableFormat::make($state)->format());
});
return $this;
});
VariablesSelector::macro('appendToContent', function () {
$this
->live(onBlur: true)
->afterStateUpdated(function (string $operation, $state, Set $set, Get $get) {
$set('content', $get('content') . ' ' . ExcerptVariableFormat::make($state)->format());
});
return $this;
});
1 replies