Skip to content

Commit

Permalink
updated multivalue.html
Browse files Browse the repository at this point in the history
  • Loading branch information
smithdc1 committed Feb 12, 2020
1 parent 9b767ee commit f410c27
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion crispy_forms/templates/bootstrap4/layout/multivalue.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="form-row">
{% for subfield in field.field.fields %}
<div class="
{% if 'col' in field_class %}{{ field_class }}{% else %} col-md{% endif %} {% if not forloop.last %}form-group {% endif %}">
{% if 'col' in field_class %}{{ field_class }}{% else %} col-md{% endif %} {% if not forloop.last %}form-group {% endif %} ">
{% if subfield|is_checkbox %}
<div class="form-check">
{% render_multi_field field forloop.counter0 'class' 'form-check-input' %}
Expand Down
16 changes: 6 additions & 10 deletions crispy_forms/templatetags/crispy_forms_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,13 @@ def render(self, context):
else:
data = bounded_field.data[field_index]



# If template pack has been overridden in FormHelper we can pick it from context
template_pack = context.get('template_pack', TEMPLATE_PACK)

# There are special django widgets that wrap actual widgets,
# such as forms.widgets.MultiWidget, admin.widgets.RelatedFieldWidgetWrapper
widgets = getattr(field.widget, 'widgets', [getattr(field.widget, 'widget', field.widget)])
widgets = getattr(bounded_field.field.widget, 'widgets',
[getattr(bounded_field.field.widget, 'widget', bounded_field.field.widget)])

if isinstance(attrs, dict):
attrs = [attrs] * len(widgets)
Expand Down Expand Up @@ -376,12 +375,9 @@ def render(self, context):
widget.attrs['class'] = css_class

# HTML5 required attribute
if html5_required and field.required and 'required' not in widget.attrs:
if html5_required and bounded_field.field.required and 'required' not in widget.attrs:
if field.widget.__class__.__name__ != 'RadioSelect':
widget.attrs['required'] = 'required'

if widget.is_required:
widget.attrs['required'] = True
widget.attrs['required'] = True

for attribute_name, attribute in attr.items():
attribute_name = template.Variable(attribute_name).resolve(context)
Expand All @@ -391,5 +387,5 @@ def render(self, context):
else:
widget.attrs[attribute_name] = template.Variable(attribute).resolve(context)

return widget.render('%s_%d' % (bounded_field.html_name, field_index),
data, widget.attrs)
return widgets[field_index].render('%s_%d' % (bounded_field.html_name, field_index),
data, widgets[field_index].attrs)
2 changes: 1 addition & 1 deletion crispy_forms/tests/test_form_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_inputs(settings):
assert 'btn btn-primary' in html
assert 'btn btn-inverse' in html
if settings.CRISPY_TEMPLATE_PACK == 'bootstrap4':
assert len(re.findall(r'<input[^>]+> <', html)) == 9
assert len(re.findall(r'<input[^>]+> <', html)) == 10
else:
assert len(re.findall(r'<input[^>]+> <', html)) == 8

Expand Down
2 changes: 0 additions & 2 deletions crispy_forms/tests/test_layout_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def test_multiwidget_field():
c = Context({'form': test_form})

html = template.render(c)
print(html)
assert html.count('class="dateinput') == 1
assert html.count('rel="test_dateinput"') == 1
assert html.count('rel="test_timeinput"') == 2
Expand All @@ -74,7 +73,6 @@ def test_field_type_hidden():
'test_form': test_form,
})
html = template.render(c)

# Check form parameters
assert html.count('data-test="12"') == 1
assert html.count('name="email"') == 1
Expand Down

0 comments on commit f410c27

Please sign in to comment.