How in tiptap editor to set maxLength

I am using the tiptap editor and somehow when i set the maxLength for the content i get the error that there is not a function maxLength, i search in docs but there is not a function for the limit of content so what i should do
6 Replies
mile4841
mile48412w ago
I tried uing this way but does not work
TiptapEditor::make('description')
->profile('default')
->extraInputAttributes(['style' => 'min-height: 350px;'])
->maxContentWidth('full')
->rules(['max:200'])
->required(),
TiptapEditor::make('description')
->profile('default')
->extraInputAttributes(['style' => 'min-height: 350px;'])
->maxContentWidth('full')
->rules(['max:200'])
->required(),
toeknee
toeknee2w ago
Because the field doesn't support it. You can make a PR
mile4841
mile48412w ago
Yeah but i was thinking they will make something else, i find the solution
->rules([
'required',
fn (): Closure => function (string $attribute, $value, Closure $fail) {
if (isset($value['content'][0]['content'][0]['text']) && strlen($value['content'][0]['content'][0]['text']) > 200) {
$fail(__("validation.max-length-seo-desc-tiptap", ["limit"=>200]));
}
},
]),
->rules([
'required',
fn (): Closure => function (string $attribute, $value, Closure $fail) {
if (isset($value['content'][0]['content'][0]['text']) && strlen($value['content'][0]['content'][0]['text']) > 200) {
$fail(__("validation.max-length-seo-desc-tiptap", ["limit"=>200]));
}
},
]),
mile4841
mile48412w ago
No description
mile4841
mile48412w ago
max:200 is not working.
awcodes
awcodes2w ago
Max length isn’t going to work correctly with a wysiwyg style editor because the state is either going to a json tree or html both of which have characters that are part of the length but hidden therefore it won’t result in a proper validation. It was a conscious decision to not include it.
Want results from more Discord servers?
Add your server