If I exceed the character count for a field on a form, I don’t receive errors when I try to submit the form.
This is confusing as the form’s fields indicate and allow me to enter characters beyond the capacity of the model’s field.
For example, on my model :
intro = RichTextField(max_length=300) #lede
My form :
I’m sure this is solvable. If anyone has done so, please let me know.
I’m not using a custom form. I’m using CBVs with bog-standard form.
Thanks
django-ckeditor’s RichTextField
extends models.TextField
. Maybe the max_length
argument doesn’t do anything for text fields?
You could try using
from django.core import validators
....
class ...
intro = RichTextField(validators=[django.core.validators.MaxLengthValidator(300)])
Or maybe write your own validator which strips tags and (some) whitespace first before applying the character limit.
1 Like
Thanks for the feedback.
After examining the HTML produced I realised that the errors were produced but when they are displayed they are being hidden behind the actual editor.
I “fixed” this with some custom css.
.invalid-feedback {
display: block;
}
I still need to make the editor smaller, though
1 Like
In case it’s helpful to anyone else, I used this code to put a red border around the ckeditor fields:
{% block css %}
<style>
{# Make error messages show up below CKEditor fields #}
.invalid-feedback {
display: block;
}
{# Force borders around the CKEditor fields with errors #}
{% for error in form.errors %}
div[data-field-id="id_{{ error }}"] {
border: red thin solid;
}
{% endfor %}
</style>
{% endblock css %}