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

Rendering issue with Layout MultiWidgetField #804

Open
chris246 opened this issue Mar 25, 2018 · 3 comments
Open

Rendering issue with Layout MultiWidgetField #804

chris246 opened this issue Mar 25, 2018 · 3 comments

Comments

@chris246
Copy link

  • Package version: 1.7.2
  • Django version: 2.0.3
  • Python version: 3.6.0
  • Template pack: (Optional) boostrap4

Description:

In my form, I use django.forms.widgets.SplitDateTimeWidget on a django.forms.ModelForm.SplitDateTimeField:

event_begin = forms.SplitDateTimeField()

Rendering the form as crispy-form using

self.helper = FormHelper()
self.helper.layout = Layout(
	Field('name'),
	MultiWidgetField('event_begin'),
)

results in this output:
grafik
(The Name field is rendered as expected)

The generated HTML:

<form method="post">
	<input name="csrfmiddlewaretoken" value="..." type="hidden">
	<div id="div_id_name" class="form-group">
		<label for="id_name" class="col-form-label  requiredField">
			Name<span class="asteriskField">*</span>
		</label>
		<div class="">
			<input name="name" value="asdasd" maxlength="45" class="textinput textInput form-control" required="" id="id_name" type="text">
		</div>
	</div>
	<div id="div_id_event_begin" class="form-group">
		<label for="id_event_begin_0" class="col-form-label  requiredField">
			Event begin<span class="asteriskField">*</span>
		</label>
		<div class="">
			<input name="event_begin_0" value="15.01.2018" class="dateinput" required="" id="id_event_begin_0" type="text">
			<input name="event_begin_1" value="22:15:00" class="timeinput" required="" id="id_event_begin_1" type="text">
		</div>
	</div>
</form>

The rendered MultiWidgetField is missing the bootstrap classes in the input elements.

Also, I would like to use PrependedText on both input elements. Is this possible?

Related to #668

@dwasyl
Copy link

dwasyl commented Jan 6, 2019

This issue presents itself when using a few other packages (i.e. django-money or django-phone-field), in both cases (like the above) MultiWidgetField is used to combine two other fields - in this case two forms.TextInput widgets.

The template (at least in the case of django-phone-field is a simple:
{% spaceless %}{% for widget in widget.subwidgets %}{% include widget.template_name %}{% if forloop.first %}&nbsp;&nbsp;ext.&nbsp;&nbsp;{% endif %}{% endfor %}{% endspaceless %}

For whatever reason, when accessing widget.template_name as part of the MultiWidget Django picks up the original field template name and not the one specified by crispy-forms. Due to the combined nature just changing the templates may not render everything properly (combined DIVs etc), but it would be a good start.

Any idea why crispy-forms template isn't picked up when accessing it this way?

Edit: Overriding the template at the crispy-forms level is a challenge as it doesn't all access to the .widgets property (for rendering the widgets individually as well as any properties). Based on #183 overriding the widget template might get ignored anyway.

@lggwettmann
Copy link

Any update on this?

@smithdc1
Copy link
Member

smithdc1 commented May 5, 2020

These fields are complex. #976 begins work on this, any comments would be much welcomed.

Others have used js to fix it in the meantime.

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

4 participants