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

why is is-valid added to form fields by default? #276

Open
timrichardson opened this issue Apr 18, 2021 · 5 comments
Open

why is is-valid added to form fields by default? #276

timrichardson opened this issue Apr 18, 2021 · 5 comments

Comments

@timrichardson
Copy link

I change to bootstrap4 from bootstrap3. I have a filter form on top of a table, rendered with

{% if filter %}
    <form action="" method="get" class="form form-inline">
        {% bootstrap_form filter.form layout='inline' %}
        {% bootstrap_button 'filter' %}
    </form>
{% endif %}

The field is rendered as

<input .... class="form-control is-valid"...>

the is-valid class means my field gets a big green tick even on the first page load (before submit)
Bootstrap3 didn't do this decoration.
I realise I can prevent is-valid via settings for the BOOTSTRAP4 app, but why is this the default?

image

@dyve
Copy link
Member

dyve commented Apr 18, 2021

Yes, for GET forms this is very illogical, I agree. Use the workaround for now, I'm working on the similar problem in django-bootstrap5, and I'll see if I can backport it once it's fixed there.

@timrichardson
Copy link
Author

Thanks for the fast update. Can you update this issue if you fix the bootstrap5 version, in case you don't have time to backport it, I will try a PR.

@dyve
Copy link
Member

dyve commented May 1, 2021

Looking at https://getbootstrap.com/docs/4.6/components/forms/#validation, it seems Bootstrap 4 advises against server side validation. A solution would be to default to False in the settings, have True lead to the default Bootstrap class(es), and allow a string to customize the valid/invalid classes.

@timrichardson
Copy link
Author

Note that I got a stackoverflow answer https://stackoverflow.com/a/67145950/401226 which suggests:
A workaround less dramatic than changing global defaults is:
" you can pass the class that should be rendered instead as the keyword argument bound_css_class to the bootstrap_form template tag:

{% bootstrap_form filter.form layout='inline' bound_css_class='' %}
"
which is not well documented (or documented at all).

However, this doesn't address the question of a sensible default.
It seems to me that if you're using Django you are likely to use server-side validation.
But why has the behaviour changed between bootstrap3 and 4?

@dyve
Copy link
Member

dyve commented May 2, 2021

I may have to recheck, but I think this behavior was (at least originally) the same in django-bootstrap3. Bootstrap 4 does have a much more visible "Validated" look (Bootstrap 3 just does a green line around the field).

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

No branches or pull requests

2 participants