Issue #6 open

Not able to add class on label

ansu jain
created an issue

When I am adding class {{{ {{form.company_name.label_tag }} }}} like {{{ {{form.company_name.label_tag|add_class:"label-field" }} }}} its give error but when i am adding class {{{ {{form.company_name|add_class:"label-field" }} }}} its work fine. Is it bug in this library

Comments (7)

  1. Mikhail Korobov repo owner

    This would be nice if library could handle field labels as well as field widgets, but it is not a bug, it is a feature that is currently not implemented in django-widget-tweaks.

    I also sometimes want to add classes to field labels using the same syntax and maybe will eventually implement it, but there is no timeline for this; patches or pull requests are very welcome!

  2. k4ml

    I was about to work on patches for this but then realize rendering the label manually not bad either:-

    <div class="form-group">
        <label class="col-sm-2 control-label" for="{{ form_field.auto_id }}">{{ form_field.label }}</label>
        <div class="col-sm-8">
        {% render_field form_field class+="form-control" %}
        </div>
    </div>
    

    So I'm not sure it worth the patch or not.

    http://stackoverflow.com/questions/4124220/django-adding-css-classes-when-rendering-form-fields-in-a-template#comment29325586_7323105

  3. Mikhail Korobov repo owner

    Template filter for setting a class for field label saves some typing, and it is more DRY. It means less chances to make an error. I still think it would be a nice feature, and that it worths a patch.

    You're right that it is indeed not hard to write label tag manually, but writing raw html for form fields themselves is also not hard.

    By the way, thanks for posting a code snippet here!

  4. Log in to comment