Giter Site home page Giter Site logo

Comments (5)

kmike avatar kmike commented on June 27, 2024

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.

kmike avatar kmike commented on June 27, 2024

Sorry, I misread the original report. This is indeed counter-intuitive.

from django-widget-tweaks.

kmike avatar kmike commented on June 27, 2024

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.

treyhunner avatar treyhunner commented on June 27, 2024

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.

kmike avatar kmike commented on June 27, 2024

I take a step further and document the current filter application order. Thanks for raising this issue!

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.