Skip to content

RichTextarea not displaying correctly in a Bootstrap modal #103

@gustavengstrom

Description

@gustavengstrom

I have the following form.

forms.py

class PersonForm(forms.Form):
    name = fields.CharField()
    text = fields.CharField(widget=RichTextarea())

which is rendered using:

urls.py

    path(
        "test_form/",
        FormView.as_view(
            form_class=PersonForm,
            template_name="test_form/test_form.html",
            success_url="/test_form/",
        ),
    ),

test_form.html (modal code copied from: Bootstrap docs)

{% load static %}
{% load render_form from formsetify %}
<!DOCTYPE html>
<html dir="ltr" lang="{{ LANGUAGE_CODE|default:'en' }}">

<head>
	<meta charset="utf-8"/>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0"/>
	<title>Django-Formset Demo</title>
	<link href="{% static 'vendor/bootstrap/dist/css/bootstrap.min.css' %}" rel="stylesheet" type="text/css" media="screen">
	<script type="module" src="{% static 'formset/js/django-formset.js' %}"></script>
</head>

<body>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title fs-5" id="exampleModalLabel">Modal title</h1>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <django-formset endpoint="{{ request.path }}" csrf-token="{{ csrf_token }}">
          {% render_form form "bootstrap" field_classes="mb-4" form_classes="rounded-xl" %}
          <button type="button" df-click="submit -> proceed">Submit</button>
        </django-formset>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
  Launch demo modal
</button>
</body>
<script src="{% static 'vendor/bootstrap/dist/js/bootstrap.min.js' %}"></script>
</html>

Which results in:
Screenshot 2024-01-10 at 13 00 06

Hence the Charfield renders correctly but not the RichTextarea...

p.s. Outside the model everything renders correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions