mostafaznv / nova-ckeditor

CkEditor 5 Field for Laravel Nova with Media & Snippet Browsers
https://mostafaznv.gitbook.io/nova-ckeditor/
MIT License
49 stars 20 forks source link

Unable to set value of CkEditor programmatically #130

Open webard opened 2 months ago

webard commented 2 months ago

Hello,

firstly, thank you for great package.

I noticed problem, when I try to programmatically set value of CkEditor field, nothing changes. Dynamic values are useful when we have predefined HTML templated which can be inserted directly to editor end modified by admin.

Select::make('Template', 'template')
->options([
    '1' => 'Template 1',
    '2' => 'Template 2',
]),

CkEditor::make('Notes', 'notes')
    ->rules('required')
    ->dependsOn(['template'], function (CkEditor $field, NovaRequest $request, FormData $formData) {

        $tpl = $formData->get('template');

        if ($tpl === '1') {

            $field->setValue('<h1>Template 1</h1>');
        }
    })