{ "info": { "author": "Simon Hanna", "author_email": "simhnna@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", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# django-widgets-improved\n\n[](https://travis-ci.org/simhnna/django-widgets-improved)\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\n\nThis project is a fork of the unmaintained [django-widget-tweaks](https://github.com/jazzband/django-widget-tweaks) repository.\nIt is a drop-in replacement. Just unintall django-widget-tweaks and install this instead.\n\n## Installation\n\nYou can get Django Widget Tweaks by using pip::\n\n $ pip install django-widgets-improved\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```\n INSTALLED_APPS = [\n ...\n 'widget_tweaks',\n ...\n ]\n```\n\n## Usage\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\n### render_field\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```\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\n### attr\nAdds or replaces any single html atribute 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### add_class\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```\n\n### set_data\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```\n\n### append_attr\n\nAppends atribute 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### add_error_class\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\n### add_error_attr\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```\n\n### field_type and widget_type\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