Skip to content

Instantly share code, notes, and snippets.

@smithdc1
smithdc1 / gist:159f45831a2ce103331c2c9ac20d49dd
Created July 1, 2020 19:23
Django Pull #12752 with Crispy-forms
============================= test session starts =============================
platform win32 -- Python 3.9.0a6, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
django: settings: crispy_forms.tests.test_settings (from option)
rootdir: C:\Users\smith\PycharmProjects\django-crispy-forms, inifile: setup.cfg
plugins: cov-2.8.1, django-3.9.0
collected 556 items
crispy_forms\tests\test_dynamic_api.py ................................. [ 5%]
............................................................sss [ 17%]
crispy_forms\tests\test_form_helper.py ................................. [ 23%]
@smithdc1
smithdc1 / fields.py
Last active April 13, 2020 12:18
Add `required` attribute to MultiValueFields
def __init__(self, fields, *, require_all_fields=True, **kwargs):
self.require_all_fields = require_all_fields
super().__init__(**kwargs)
# We have two sets of widgets. Each field in fields has a widget whilst self.widget is probably our `MultiWidget`
# We're interested in the MultiWidget as this is what is rendered.
# Let's loop over fields and the MultiWidget and set required on the subwidgets.
for field, widget in zip(fields, self.widget.widgets):
field.error_messages.setdefault('incomplete',
self.error_messages['incomplete'])