TipTap RichEditor: "flatten" or navigate tree for text validation
When implementing a custom validation rule for a RichEditor with a signature like
fn(string $attribute, $value, Closure $fail)
, under Filament v3 with the Trix editor, the $value
contains a string representation of the editor's content; with Filament v4 (TipTap), it's a tree structure with nodes for text, images, paragraphs, and so on.
Is there a way to restore the v3 functionality, where the validation rule can access the entire contents as a string? If not, can anyone point me towards documentation of the tree structure used by TipTap so I can implement logic correctly examine each text node?2 Replies
What exactly are you trying to validate? If you want to validate against the html you will need to run the $state through the a RichContentRenderer to convert it to html.
Thanks for the suggestion about
$state
and the RichContentRenderer. In this case, it's a string of HTML-like text, with some custom macros. The validation rule accepts a string and fails if any unknown macros are detected. Under Filament v3, these "custom macros" were implemented with regex-based find-and-replace. Perhaps I should be looking to RichContentCustomBlock
under v4 instead.