django-bootstrap4 icon indicating copy to clipboard operation
django-bootstrap4 copied to clipboard

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

Open timrichardson opened this issue 4 years ago • 5 comments

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

timrichardson avatar Apr 18 '21 07:04 timrichardson

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.

dyve avatar Apr 18 '21 07:04 dyve

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.

timrichardson avatar Apr 18 '21 08:04 timrichardson

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.

dyve avatar May 01 '21 05:05 dyve

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?

timrichardson avatar May 01 '21 21:05 timrichardson

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).

dyve avatar May 02 '21 09:05 dyve