{ "info": { "author": "Mikhail Korobov", "author_email": "kmike84@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "====================\ndjango-widget-tweaks\n====================\n\n.. image:: https://jazzband.co/static/img/badge.svg\n :target: https://jazzband.co/\n :alt: Jazzband\n\n.. image:: https://img.shields.io/pypi/v/django-widget-tweaks.svg\n :target: https://pypi.python.org/pypi/django-widget-tweaks\n :alt: PyPI Version\n\n.. image:: https://img.shields.io/travis/jazzband/django-widget-tweaks/master.svg\n :target: http://travis-ci.org/jazzband/django-widget-tweaks\n :alt: Build Status\n\n\nTweak the form field rendering in templates, not in python-level\nform definitions. Altering CSS classes and HTML attributes is supported.\n\nThat should be enough for designers to customize field presentation (using\nCSS and unobtrusive javascript) without touching python code.\n\nLicense is MIT.\n\nInstallation\n============\n\nYou can get Django Widget Tweaks by using pip::\n\n $ pip install django-widget-tweaks\n\nTo enable `widget_tweaks` in your project you need to add it to `INSTALLED_APPS` in your projects\n`settings.py` file::\n\n INSTALLED_APPS = [\n ...\n 'widget_tweaks',\n ...\n ]\n\nUsage\n=====\n\nThis app provides two sets of tools that may be used together or standalone:\n\n1. a ``render_field`` template tag for customizing form fields by using an\n HTML-like syntax.\n2. several template filters for customizing form field HTML attributes and CSS\n classes\n\nThe ``render_field`` tag should be easier to use and should make form field\ncustomizations much easier for designers and front-end developers.\n\nThe template filters are more powerful than the ``render_field`` tag, but they\nuse a more complex and less HTML-like syntax.\n\nrender_field\n------------\n\nThis is a template tag that can be used as an alternative to aforementioned\nfilters. This template tag renders a field using a syntax similar to plain\nHTML attributes.\n\nExample::\n\n {% load widget_tweaks %}\n\n \n {% render_field form.search_query type=\"search\" %}\n\n \n {% render_field form.text rows=\"20\" cols=\"20\" title=\"Hello, world!\" %}\n\n \n {% render_field form.title class+=\"css_class_1 css_class_2\" %}\n\n \n {% render_field form.text placeholder=form.text.label %}\n\n \n {% render_field form.search_query v-bind::class=\"{active:isActive}\" %}\n\n\nFor fields rendered with ``{% render_field %}`` tag it is possible\nto set error class and required fields class by using\n``WIDGET_ERROR_CLASS`` and ``WIDGET_REQUIRED_CLASS`` template variables::\n\n {% with WIDGET_ERROR_CLASS='my_error' WIDGET_REQUIRED_CLASS='my_required' %}\n {% render_field form.field1 %}\n {% render_field form.field2 %}\n {% render_field form.field3 %}\n {% endwith %}\n\nYou can be creative with these variables: e.g. a context processor could\nset a default CSS error class on all fields rendered by\n``{% render_field %}``.\n\n\nattr\n----\nAdds or replaces any single html attribute for the form field.\n\nExamples::\n\n {% load widget_tweaks %}\n\n \n {{ form.search_query|attr:\"type:search\" }}\n\n \n {{ form.text|attr:\"rows:20\"|attr:\"cols:20\"|attr:\"title:Hello, world!\" }}\n\n \n {{ form.search_query|attr:\"autofocus\" }}\n\n\n \n {{ form.search_query|attr:\"v-bind::class:{active:ValueEnabled}\" }}\n\n\nadd_class\n---------\n\nAdds CSS class to field element. Split classes by whitespace in order to add\nseveral classes at once.\n\nExample::\n\n {% load widget_tweaks %}\n\n \n {{ form.title|add_class:\"css_class_1 css_class_2\" }}\n\nset_data\n--------\n\nSets HTML5 data attribute ( http://ejohn.org/blog/html-5-data-attributes/ ).\nUseful for unobtrusive javascript. It is just a shortcut for 'attr' filter\nthat prepends attribute names with 'data-' string.\n\nExample::\n\n {% load widget_tweaks %}\n\n \n {{ form.title|set_data:\"filters:OverText\" }}\n\nappend_attr\n-----------\n\nAppends attribute value with extra data.\n\nExample::\n\n {% load widget_tweaks %}\n\n \n {{ form.title|append_attr:\"class:css_class_1 css_class_2\" }}\n\n'add_class' filter is just a shortcut for 'append_attr' filter that\nadds values to the 'class' attribute.\n\n\nadd_label_class\n---------------\n\nThe same as `add_class` but adds css class to form labels.\n\nExample::\n\n {% load widget_tweaks %}\n\n \n {{ form.title|add_label_class:\"label_class_1 label_class_2\" }}\n\n\nadd_error_class\n---------------\n\nThe same as 'add_class' but adds css class only if validation failed for\nthe field (field.errors is not empty).\n\nExample::\n\n {% load widget_tweaks %}\n\n \n {{ form.title|add_error_class:\"error-border\" }}\n\n\nadd_error_attr\n--------------\n\nThe same as 'attr' but sets an attribute only if validation failed for\nthe field (field.errors is not empty). This can be useful when dealing\nwith accessibility::\n\n {% load widget_tweaks %}\n\n \n {{ form.title|add_error_attr:\"aria-invalid:true\" }}\n\nfield_type and widget_type\n--------------------------\n\n``'field_type'`` and ``'widget_type'`` are template filters that return\nfield class name and field widget class name (in lower case).\n\nExample::\n\n {% load widget_tweaks %}\n\n