Opened 3 years ago

Closed 19 months ago

#33386 closed Bug (needsinfo)

Autocomplete on refresh with Firefox interacts badly with ModelMultipleChoiceField in forms

Reported by: Pietro Brenna Owned by: Eknath Baravkar
Component: Forms Version: 3.2
Severity: Normal Keywords: firefox
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

Steps to reproduce:

  • visit a form containing a ModelMultipleChoiceField (such as the page for editing an auth.group in django admin) with a recent version of Firefox. The widget has two <select>s, and the second one contains the chosen elements.
  • refresh the page with f5 or the reload button
  • notice that the second <select> is now empty (no <option>s)

This causes inadvertent data loss when the user then submits the form. The behaviour can be avoided by setting autocomplete="off".

A similar behaviour is noticeable in normal <select> widgets, where the value chosen before refreshing is still selected after the refresh, regardless of the <option> selected="" attribute, although this being a bug is debatable, and certainly not limited to django.

Change History (9)

comment:1 by Mariusz Felisiak, 3 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Thanks for the report, I was able to reproduce this issue.

comment:2 by Dlis, 3 years ago

Unfortunately, Firefox has a "feature" that is associated with restoring the values of form fields. Sometimes, this behavior does not interact well with hidden fields like fields with CSRF-tokens. For example, a corresponding ticket was created more than 20 years ago (https://bugzilla.mozilla.org/show_bug.cgi?id=46845 ) and opens again from time to time.

  1. S. You can temporarily fix the problem by including a js-file with a simple sniplet like specified below in order to disable a browser-based autocomplete (https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion) and reset fields to their default states:
$('form').attr('autocomplete', 'off').each(function () {
        this.reset();
});
Last edited 3 years ago by Dlis (previous) (diff)

comment:3 by Eknath Baravkar, 19 months ago

Owner: changed from nobody to Eknath Baravkar
Status: newassigned

we can disable autocomplete field in python django as below:

hidden_widget = MultipleHiddenInput(attrs={'autocomplete': 'off'})
widget = SelectMultiple(attrs={'autocomplete': 'off'})

As well as we have one more option to set widget-
autocomplete = False like is_localized = False, is_required = False and so on..

Last edited 19 months ago by Eknath Baravkar (previous) (diff)

comment:4 by Eknath Baravkar, 19 months ago

Triage Stage: AcceptedReady for checkin

we can disable autocomplete field in python django as below:

hidden_widget = MultipleHiddenInput(attrs={'autocomplete': 'off'})
widget = SelectMultiple(attrs={'autocomplete': 'off'})

As well as we have one more option to set widget-
autocomplete = False like is_localized = False, is_required = False and so on..

comment:5 by Mariusz Felisiak, 19 months ago

Triage Stage: Ready for checkinAccepted

Eknath, this ticket doesn't have submitted and reviewed PR, please check Triaging tickets docs.

in reply to:  5 comment:6 by Eknath Baravkar, 19 months ago

Hi Mariusz Felisiak, Thanks for replay. I am first time contributor; I will work on the same.

comment:7 by Eknath Baravkar, 19 months ago

Has patch: set

Add patch Please check PR as below:
https://github.com/django/django/pull/16418

comment:8 by Mariusz Felisiak, 19 months ago

I can no longer reproduce this issue on Firefox 108.0.1.

comment:9 by Mariusz Felisiak, 19 months ago

Has patch: unset
Resolution: needsinfo
Status: assignedclosed
Triage Stage: AcceptedUnreviewed

Closing as "needsinfo" unless someone can reproduce it with "the recent versions of modern, web standards compliant browsers".

Note: See TracTickets for help on using tickets.
Back to Top