Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML Validation does not work with CKEditor Widgets because the textarea is hidden when it is replaced with ckeditor #251

Closed
jaredmdunn opened this issue Sep 26, 2024 · 2 comments

Comments

@jaredmdunn
Copy link
Contributor

jaredmdunn commented Sep 26, 2024

When I create a required field using the CKEditor5Widget within a form that does not specify novalidate, the console throws this error on submit:
image
This happens whether or not the ckeditor field is empty because the textarea is not filled until after submit.

The expected behavior would be for the ckeditor field that replaces the textarea to work with HTML validation. Either way, this should be documented.

Potential Partial Fix:

On editor creation, add an event listener to populate the textarea while the ckeditor is being worked in (on input or change). I believe this would prevent the error from blocking submits if the ckeditor has content in it when a field is required. It would not solve the issue when there is an error detected in the ckeditor/textarea.

@goapunk
Copy link
Contributor

goapunk commented Oct 1, 2024

I agree, this should be documented. Is there any real benefit on having the brower side validation for the ckeditor field though? We could add formnovalidate to the widget template I think, this way you don't need to add novalidate to the whole form if you want to keep the browser validation for the other form fields.

@jaredmdunn
Copy link
Contributor Author

@goapunk I think you are right that having browser side validation is not necessary. In my own project, we ended up setting Django's use_required_attribute to False, which is recommended in the Django documentation. I think formnovalidate would work as well.

hvlads added a commit that referenced this issue Oct 12, 2024
…ea-validation

fix: sync CKEditor content with textarea for form validation (#251)
@hvlads hvlads closed this as completed Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants