question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tailwind forms styling not applied correctly

See original GitHub issue

Hi

I’ve installed tailwind, crispy_forms & crispy_tailwind but the form styling doesn’t seem to be working and I get huge SVG arrow appearing underneath.

crispytailwind

settings.py

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'tailwind',
        'theme',
        'crispy_forms',
        'crispy_tailwind',
        'accs',
        'user',
    ]
...
CRISPY_ALLOWED_TEMPLATE_PACKS = "tailwind"
CRISPY_TEMPLATE_PACK = "tailwind"
...

my_form_template.html

{% extends 'core/base.html' %}
{% load tailwind_filters %}

{% block content %}

   <div class="container mx-auto">
    <h2 class="text-lg text-gray-900 font-bold text-xl pt-4">Edit Payee</h2>
   <hr class="pt-4 border-gray-900">
   </div>
    <form action="" method="post">{% csrf_token %}
      {{ form|crispy }}
      <input class="text-base bg-transparent hover:bg-blue-400 text-blue-400 font-semibold hover:text-white py-2 px-4 border border-blue-400 hover:border-transparent rounded" type="submit" value="Update">
    </form>

{% endblock content %}

I’ve tried with/without the form tags and with/without {% load crispy_forms_tags %} - neither have any effect. Any ideas what I’m missing?

Thanks

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
farhanmasudcommented, Feb 8, 2022

I had the same problem. Fixed it by overriding the crispy_tailwind/templates/tailwind/layout/select.html file as following -

{% load crispy_forms_filters %}
{% load l10n %}

<div class="relative">
<select class="{% if field.errors %}border border-red-500 {% endif %}bg-white focus:outline-none border border-gray-300 rounded-lg py-2 px-4 block w-full appearance-none leading-normal text-gray-700" name="{{ field.html_name }}" {{ field.field.widget.attrs|flatatt }}>
    {% for value, label in field.field.choices %}
        {% include "tailwind/layout/select_option.html" with value=value label=label %}
    {% endfor %}
</select>
</div>
</div>

This new file will need to be saved at templates/tailwind/layout/select.html file. Here I have just removed the div containing the svg icon for the dropdown.

The following is the original code from crispy_tailwind/templates/tailwind/layout/select.html file -

{% load crispy_forms_filters %}
{% load l10n %}

<div class="relative">
<select class="{% if field.errors %}border border-red-500 {% endif %}bg-white focus:outline-none border border-gray-300 rounded-lg py-2 px-4 block w-full appearance-none leading-normal text-gray-700" name="{{ field.html_name }}" {{ field.field.widget.attrs|flatatt }}>
    {% for value, label in field.field.choices %}
        {% include "tailwind/layout/select_option.html" with value=value label=label %}
    {% endfor %}
</select>
<div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-700">
    <svg class="fill-current h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"/></svg>
  </div>
</div>
</div>

Also, the following should be in your template settings.

"DIRS": [
            BASE_DIR / "templates",
        ],
1reaction
farhanmasudcommented, Feb 20, 2022

@tobyporter I had the same problem. Go into your tailwind.config.js and comment out require('@tailwindcss/forms'). At least that worked for me.

After tinkering around with the issue, I think this should be the solution. The issue is not with crispy-tailwind. The issue is coming form the form styling of django-tailwind.

This tailwind.config.js file resides in theme/static_src directory.

Read more comments on GitHub >

github_iconTop Results From Across the Web

tailwind form not positioning properly as fixed element
I'm using tailwind css to style a ...
Read more >
How to Style a Form With Tailwind CSS
For example, applying a class like .text-center to an element means that we're setting its text-align property to center . Simple enough, right?...
Read more >
Styling Forms with Tailwind CSS - YouTube
In this video, we look at how to style form elements in Tailwind CSS using utility classes, and how the official `@tailwindcss/ forms...
Read more >
Debugging Tailwind CSS and Next.js - LogRocket Blog
Not having the Tailwind directives in the main CSS file · Not assigning the CSS classes correctly to the elements · Using the...
Read more >
Browser Support - Tailwind CSS
If you're using the Tailwind CLI tool, vendor prefixes like this will be added automatically. If not, we recommend that you use Autoprefixer,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found