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

add another filter add_valid_class? #126

Open
BoPeng opened this issue May 2, 2022 · 0 comments
Open

add another filter add_valid_class? #126

BoPeng opened this issue May 2, 2022 · 0 comments

Comments

@BoPeng
Copy link

BoPeng commented May 2, 2022

bootstrap allows the use of is-valid and is-invalid for fields of validated forms (bounded). Whereas is-invalid class can be easily added as

 {% render_field form.field1|add_error_class:'is-invalid' %}

It is not easy to do so with is-valid because blindly adding the class will mark fields as valid for unbounded forms.

Is it possible to add another filter called add_valid_class as follows?

@register.filter("add_valid_class")
@silence_without_field
def add_valid_class(field, css_class):
    if field.form.is_bound and not (hasattr(field, "errors") and field.errors):
        return add_class(field, css_class)
    return 

I suppose it also makes sense to add WIDGET_VALID_CLASS so that I can do

{% with WIDGET_ERROR_CLASS='is-invalid' WIDGET_VALID_CLASS="is-valid" %}
    {% render_field form.field1 %}
    {% render_field form.field2 %}
    {% render_field form.field3 %}
{% endwith %}
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