ckeditor / ckeditor5

Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.
https://ckeditor.com/ckeditor-5
Other
9.52k stars 3.7k forks source link

Validation rules on editable widgets #15364

Open Kocal opened 11 months ago

Kocal commented 11 months ago

📝 Provide a description of the new feature

Hi everyone! I'm sorry if this issues is duplicated, but I didn't find anything there on GitHub nor on documentation.

While implementing a custom BlockQuote plugin (when following https://ckeditor.com/docs/ckeditor5/latest/tutorials/widgets/implementing-a-block-widget.html), with 3 editable widgets:

https://github.com/ckeditor/ckeditor5/assets/2103975/69996f7b-ed42-4beb-b960-0683471fb1c2

I was wondering if it's possible to attach validation rules to editable widget?

Like, here, I would like to mark the content editable widget as required, if it's not filled then an error message should appears.

Maybe this can be added to the schema definition, or maybe an option to viewWriter.createEditableElement()?

Thanks :)


If you'd like to see this feature implemented, add a 👍 reaction to this post.

Witoso commented 11 months ago

Thanks for the request!

if it's not filled then an error message should appears.

I wonder how the logic for this would be implemented. It's also not filled when you create a widget. What's the trigger for that? What do you mean by error?

Kocal commented 11 months ago

Hi!

I wonder how the logic for this would be implemented. It's also not filled when you create a widget

I know some form validation library works with a state "touched" or "dirty", to know if the user typed in the field or not.

What's the trigger for that?

I suppose this can be done on keyup, maybe with a configurable debounce.

Or, maybe this can be triggered when a form is submitted/an action is performed? An HTML5 could block the form submission.

What do you mean by error?

A red text below the field, telling the user what's wrong with the value.