$rawState Error with RichEditor

Hi, I have a problem with my RichEditor. I use a relationship in my model form and when I save it without changing the text in the RichEditor than I get this error: Filament\Forms\Components\RichEditor::Filament\Forms\Components{closure}(): Argument #2 ($rawState) must be of type ?array, string given, called in /vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 36 I found some work arounds but they didn't work. https://github.com/filamentphp/filament/issues/17472
public function mount($record): void
{
parent::mount($record);

/** @var Coach $model */
$model = $this->record;

// Convert HTML to Tiptap JSON for RichEditor
if ($model->listingProfile && is_string($model->listingProfile->about_us) && ! empty($model->listingProfile->about_us)) {
$editor = new Editor([
'extensions' => [
new StarterKit(),
],
]);

$editor->setContent($model->listingProfile->about_us);

// Setze die konvertierten Daten direkt im Form-State
$this->data['listingProfile']['about_us'] = $editor->getDocument();
dump($editor);
}
}
public function mount($record): void
{
parent::mount($record);

/** @var Coach $model */
$model = $this->record;

// Convert HTML to Tiptap JSON for RichEditor
if ($model->listingProfile && is_string($model->listingProfile->about_us) && ! empty($model->listingProfile->about_us)) {
$editor = new Editor([
'extensions' => [
new StarterKit(),
],
]);

$editor->setContent($model->listingProfile->about_us);

// Setze die konvertierten Daten direkt im Form-State
$this->data['listingProfile']['about_us'] = $editor->getDocument();
dump($editor);
}
}
GitHub
[v4.x] Error on testing a RichEditor component · Issue #17472 · f...
Package filament/forms Package Version v4.0.3 Laravel Version v12.25.0 Livewire Version v3.6.4 PHP Version 8.4.11 Problem description On testing a RichEditor component I get the following error: Fi...
1 Reply
Pascal
PascalOP4w ago
OMG. I found another workaround now. EditCoach.php (In Resource)
public array $aboutUs = [];

public function mount($record): void
{
parent::mount($record);

/** @var Coach $model */
$model = $this->record;

// Convert HTML to Tiptap JSON for RichEditor
if ($model->listingProfile && is_string($model->listingProfile->about_us) && ! empty($model->listingProfile->about_us)) {
$editor = new Editor([
'extensions' => [
new StarterKit,
],
]);

$editor->setContent($model->listingProfile->about_us);

$this->data['aboutUs'] = $editor->getDocument();
}
}

public function afterSave(): void
{
$rawState = $this->form->getRawState();

/** @var Coach $model */
$model = $this->record;


if (isset($rawState['aboutUs']) && is_array($rawState['aboutUs'])) {
$aboutUs = $rawState['aboutUs'];

if (isset($aboutUs['type']) && $aboutUs['type'] === 'doc') {
$editor = new Editor([
'extensions' => [
new StarterKit,
],
]);

$editor->setContent($aboutUs);

$model->listingProfile->about_us = $editor->getHTML();
$model->listingProfile->save();
}
}
}
public array $aboutUs = [];

public function mount($record): void
{
parent::mount($record);

/** @var Coach $model */
$model = $this->record;

// Convert HTML to Tiptap JSON for RichEditor
if ($model->listingProfile && is_string($model->listingProfile->about_us) && ! empty($model->listingProfile->about_us)) {
$editor = new Editor([
'extensions' => [
new StarterKit,
],
]);

$editor->setContent($model->listingProfile->about_us);

$this->data['aboutUs'] = $editor->getDocument();
}
}

public function afterSave(): void
{
$rawState = $this->form->getRawState();

/** @var Coach $model */
$model = $this->record;


if (isset($rawState['aboutUs']) && is_array($rawState['aboutUs'])) {
$aboutUs = $rawState['aboutUs'];

if (isset($aboutUs['type']) && $aboutUs['type'] === 'doc') {
$editor = new Editor([
'extensions' => [
new StarterKit,
],
]);

$editor->setContent($aboutUs);

$model->listingProfile->about_us = $editor->getHTML();
$model->listingProfile->save();
}
}
}
Form field
RichEditor::make('listingProfile.about_us')
->label('Unternehmensbeschreibung')
->columnSpanFull()
->toolbarButtons([
'bold',
'italic',
'underline',
'bulletList',
'link',
])
->dehydrated(false)
->reactive()
->live()
->statePath('aboutUs');
RichEditor::make('listingProfile.about_us')
->label('Unternehmensbeschreibung')
->columnSpanFull()
->toolbarButtons([
'bold',
'italic',
'underline',
'bulletList',
'link',
])
->dehydrated(false)
->reactive()
->live()
->statePath('aboutUs');

Did you find this page helpful?