Giter Site home page Giter Site logo

Comments (8)

luanfonceca avatar luanfonceca commented on June 27, 2024 4

Or just {{ form.field.label_tag|add_class='control-label' }} like the bootstrap requires.
The label_tag is a django method used to render the label.

Update:
I did this to make it work:

# Templatetags files
@register.filter("add_label_class")
@silence_without_field
def add_label_class(field, css_class):
    return field.label_tag(attrs={'class': css_class})

# html
{{ form.field|add_label_class:'control-label' }} 

This renders: <label for="id_field" class="control-label">Field</label>

from django-widget-tweaks.

luanfonceca avatar luanfonceca commented on June 27, 2024

+1

from django-widget-tweaks.

resurtm avatar resurtm commented on June 27, 2024

Another solution is to render <field></field> tag manually. Something like this:

<div class="form-group row">
    <label for="{{ form.make.auto_id }}" class="col-sm-3 col-form-label">{{ form.make.label }}</label>
    <div class="col-sm-9">
        {% render_field form.make class+='form-control' %}
        {% include 'common/partials/field-errors.html' with errors=form.make.errors %}
    </div>
</div>

from django-widget-tweaks.

treyd avatar treyd commented on June 27, 2024

@resurtm I am using something similar to your solution... can you share what you're including with {% include 'common/partials/field-errors.html' with errors=form.make.errors %} ?

from django-widget-tweaks.

resurtm avatar resurtm commented on June 27, 2024

@treyd, oh there is nothing special inside:

{% if errors %}
    <div class="invalid-feedback">
        {% for error in errors %}
            {{ error }}
        {% endfor %}
    </div>
{% endif %}

from django-widget-tweaks.

camilonova avatar camilonova commented on June 27, 2024

It was just merged.

from django-widget-tweaks.

denizdogan avatar denizdogan commented on June 27, 2024

@camilonova This is all great, any ideas on when the next release will be out? :) Would love to use this in a new project I'm working on.

from django-widget-tweaks.

camilonova avatar camilonova commented on June 27, 2024

I'll see if I can make a release real quick

from django-widget-tweaks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.