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

Field's `show_hidden_initial` property is not being respected

Open mick88 opened this issue 3 years ago • 2 comments

Django form field has a property that can be set in constructor:

        # show_hidden_initial -- Boolean that specifies if it is needed to render a
        #                        hidden widget with initial value after widget.

When bound field is rendered by Django, it is used to append a hidden field containing the default value:

    def __str__(self):
        """Render this field as an HTML widget."""
        if self.field.show_hidden_initial:
            return self.as_widget() + self.as_hidden(only_initial=True)
        return self.as_widget()

However, when rendering form using FieldRenderer, this functionality is broken. As a result, form's changed_values contains the field even if it was not actually changed by user (assuming it already has a value)

Affected versions: Django 2.2.23 django-bootstrap3 15.0.0

mick88 avatar May 17 '21 12:05 mick88

The linked Pull Request fixes the issue for me in django 2.2. I have not tested other Django versions, but show_hidden_initial and implementetion of field render is the same in Django 2.2 and 3.2, so the fix should work for all supported versions of Django.

mick88 avatar May 17 '21 12:05 mick88

Reviving this. We should check this in 4 and 5 also. A (failing) unit test would help.

dyve avatar Aug 07 '22 07:08 dyve

No further changes are expected on this project. See README.md (https://github.com/zostera/django-bootstrap3/pull/964 ).

dyve avatar Apr 16 '24 19:04 dyve