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

Can't submit form because froala editor field is required but hidden #68

Open
engin-can opened this issue May 16, 2019 · 1 comment
Open

Comments

@engin-can
Copy link

engin-can commented May 16, 2019

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')

image

@tisdall
Copy link

tisdall commented Nov 7, 2019

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

tisdall added a commit to tisdall/django-froala-editor that referenced this issue Nov 7, 2019
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

2 participants