Comments (5)
Django widgets' 'attrs' argument is a dictionary so the order of atributes should not be relied on. This is how django widgets work so I don't think we should do anything here.
Current django-widget-tweaks tests just check if e.g. name="simple"
is in rendered widget and name='complex'
is not - this is not totally great but works good enough for tests.
django 1.4 has assertHtmlEqual that can be backported to django-widget-tweaks and used for such tests. I don't have strong opinion here but think that this may be too much.
from django-widget-tweaks.
Sorry, I misread the original report. This is indeed counter-intuitive.
from django-widget-tweaks.
Extra example to consider:
{# inc/field.html #}
{% load widget_tweaks %}
<div>{{ field|attr:"foo:default_foo" }}</div>
{# my_template.html #}
{% load widget_tweaks %}
<form method='POST' action=''> {% csrf_token %}
{% include "inc/field.html" with field=form.title %}
{% include "inc/field.html" with field=form.description|attr:"foo:non_default_foo" %}
</form>
this should work with current implementation but will not be possible if we change the direction filters are applied.
I agree that the current behavior is counter-intuitive but it seems to have its advantages. Are there use cases for the changed filter direction?
from django-widget-tweaks.
I noticed this because render_field
relies on set_attr
and append_attr
so assigning an attribute twice results in the first assignment taking precedence:
{% render_field form.simple foo="bar" foo="baz" %}
Renders
<input foo="bar" type="text" name="simple" id="id_simple" />
For render_field
I don't think this is really an issue because there is no use for multiple attribute assignment.
I have not thought of any good use for attr
chaining either.
from django-widget-tweaks.
I take a step further and document the current filter application order. Thanks for raising this issue!
from django-widget-tweaks.
Related Issues (20)
- Is it possible to add is-valid class after validation HOT 3
- Do there any blockers to bump new release? HOT 13
- Test-Suite missing in tarball HOT 1
- How to use Django template variable on attr or set_data HOT 4
- setting size of a field by accessing the model field max_length HOT 1
- accessing variables in render_field tag HOT 2
- setup.py should specify python_requires HOT 1
- Can not find module name in Django installed App HOT 5
- add another filter add_valid_class?
- WIDGET_ERROR_CLASS and WIDGET_REQUIRED_CLASS via settings HOT 1
- removing "required" from form-check-input
- Does it work on FileField? HOT 2
- widget_tweaks causes 'DeprecationWarning: pkg_resources is deprecated as an API' HOT 1
- _pickle.PicklingError: Cannot pickle ResolverMatch. HOT 1
- Releasing a new version with Django 4.2 support HOT 2
- pkg_resources error in django-widget-tweaks after upgrading to Python 3.12 on my distro (Fedora 39) HOT 2
- render_field type date doesn't respect django settings
- Use Django url tag in render_field HOT 1
- [REQUEST] Have an option to use BoundField.render() instead of str(bounded_field)
- how to hook into render_field from request
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-widget-tweaks.