jazzband / django-floppyforms

Full control of form rendering in the templates.
http://django-floppyforms.readthedocs.org/
Other
839 stars 145 forks source link

Issue with extra_views for InlineFormSet #165

Closed variable closed 8 years ago

variable commented 8 years ago

I am using extra_views in conjunction with floppyform forms.

import floppyforms.__future__ as forms

class QuoteItemForm(forms.ModelForm):
    class Meta:
        model = QuoteItem
        fields = ['section_number', 'section_description', 'variation', 'bar_description', 'length', 'nos_in_1', 'multiplier', 'supply_price_rate', 'placing_price_rate']

    supply_price_rate = forms.DecimalField(widget=forms.widgets.Input(attrs={'size': 10}), required=False)
    placing_price_rate = forms.DecimalField(widget=forms.widgets.Input(attrs={'size': 10}), required=False)

class QuoteItemInline(InlineFormSet):
    model = QuoteItem
    form_class = QuoteItemForm

class UpdateSheet(LoginRequiredMixin, UpdateWithInlinesView):
    model = Sheet
    form_class = SheetUpdateForm
    template_name = 'quotations/sheets/update.html'
    slug_url_kwarg = 'sheet_uuid'
    slug_field = 'uuid'
    inlines = [QuoteItemInline]

So this generates the inline forms, but the extra empty forms will have the html5 attribute "required" added to required fields. This results empty inline forms cannot be saved.

To solve this issue, I just needed to change from

class QuoteItemForm(forms.ModelForm):

to

from django import forms as django_forms
class QuoteItemForm(django_forms.ModelForm):

This looks like the ModelForm from floppyform package is not doing exactly the same stuff as the vanila django ModelForm.

gregmuellegger commented 8 years ago

Hi. Yes, floppyforms behaves different there as it wants to output HTML5 forms in all it's facets. The differences are documented here: http://django-floppyforms.readthedocs.org/en/latest/differences.html?highlight=novalidate Please make sure to read the section about novalidate to see how you can avoid the client side (in-browser) validation.