Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CrispyFieldNode’s attribute expansion is overly strict #1203

Open
interDist opened this issue Jan 9, 2022 · 0 comments
Open

CrispyFieldNode’s attribute expansion is overly strict #1203

interDist opened this issue Jan 9, 2022 · 0 comments

Comments

@interDist
Copy link

  • Package version: 1.12.0
  • Django version: 2.2.25

Description

The template tag {% crispy_field %} allows setting additional attributes to be rendered on the HTML tag. The expansion / resolving of the values is restricted to a variable defined in the template’s context and does not allow using filters.
This is due to the usage of template.Variable, while template.FilterExpression should have been used.

Example code:

{% crispy_field field "data-question" var_q|default_if_none:"?" %}

Expected

The resulting HTML page includes an <input> tag with data-question="?" attribute if var_q is None and with data-question="how?" attribute if var_q is "how?".

Actual behavior

The following template error:

VariableDoesNotExist

Failed lookup for key [var_q|default_if_none:"?"] in context.

Offending lines: https://github.com/django-crispy-forms/django-crispy-forms/blob/1.12.0/crispy_forms/templatetags/crispy_forms_field.py#L150-L153

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant