RichEditor in Filament v4 converting content to json by default instead of string
I have a weird situation where the same default Filament V4 RichEditors are behaving differently on two ends.
On my X page it's converting content correctly to string and on my Y page it's converting to array, but I'm not calling ->json() on it.
On my X page it's defined as
RichEditor::make('content')
->required()
->maxLength(65535)
->disableToolbarButtons([
'attachFiles',
'blockquote',
'codeBlock',
'h2',
'h3'
])
and my Y page (Multi Step form page) as
RichEditor::make('description')
->disableToolbarButtons([
'attachFiles',
'codeBlock',
'strike',
'blockquote',
'h2',
])->rules(['nullable', 'string'])
As you can see from my picture for Y page I'm getting 'description' and 'confirmation_site_message' dumped as arrays, I'm just dumping $state in afterValidation() method to get this dump. I've checked in observer, model, etc.. if we are somewhere changing the content to array, but can't find anything. I'm not sure anymore why one would convert to array and another to string, since they are pretty much identically set up.
EDIT: On page X it's also converting to array, but I didn't have a rule set on it. However, issue still remains that in Filament V4 in validation stage we now have type array and not string anymore.
3 Replies
I've noticed we are saving only the string content in DB, but if we have ->rules(['nullable', 'string']) we are getting error at this stage that the content is not a string..
This should be maybe explained in documentation a bit better, since all the rules ('string') we had/have from previous default RichEditor now don't work anymore, since the new default conversion at this stage is of type array and not string anymore.
@Dennis Koch @Leandro Ferreira this should be probably explained in documentation and a lot of people will run into this problem when upgrading from filament v3 to filament v4.
@Dan Harrin Should we cast the empty document in RichEditor to
null
?Even if we did, it wouldn't affect validation, that runs before casting