django-froala-editor
django-froala-editor copied to clipboard
Can't submit form because froala editor field is required but hidden
I have a problem where I can't submit my form because my description textarea
is required
but hidden
in my form
. Any idea how I can solve this? I have no idea where style="display:none;"
is coming from. Any idea?
class CustomFroalaEditor(FroalaEditor):
def __init__(self, *args, **kwargs):
super(CustomFroalaEditor, self).__init__(*args, **kwargs)
def render(self, name, value, attrs=None, renderer=None):
html = super(FroalaEditor, self).render(name, value, attrs)
return mark_safe(html)
class NewBlaForm(forms.ModelForm):
description = forms.CharField(widget=CustomFroalaEditor(attrs={'id': 'nb__description-editor'}))
class Meta:
model = Bla
fields = ('description')
The form should still submit if you put content within the editor. The 'required' causes html5 validation which prevents submitting the form when it's blank. However, the browser is supposed to highlight the field, but it can't because it's hidden.
Here's a workaround:
from froala_editor.widgets import FroalaEditor as OriginalFroalaEditor
class FroalaEditor(OriginalFroalaEditor):
def use_required_attribute(self, initial):
# textarea is hidden so HTML5 validation won't work properly
return False