zostera/django-bootstrap3

Field's `show_hidden_initial` property is not being respected

Closed this issue · 3 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

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.

dyve commented

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

dyve commented

No further changes are expected on this project. See README.md (#964 ).