Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#13613 closed (fixed)

forms.URLField not default ModelForm URLField anymore

Reported by: amadison Owned by: nobody
Component: Forms Version: 1.2
Severity: Keywords: ModelForm URLField
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Looks like with Changeset 11456 the ModelForm URLField stopped using the forms.FormField as it's default form field. Now it just uses a regular CharField but adds the validators.URLValidator.

There are two important things that were lost when this happened.

  1. the ModelForm does not add on the 'http://' if it is not present, so 'www.google.com' is an invalid url when using a ModelForm, but not a regular form.
  2. The error message on an invalid url is now the generic 'Enter a valid value.' instead of the more helpful 'Enter a valid URL.'.

Attached is a diff for making the ModelForm URLField use the default forms.URLField again as the docs describe here

I think this will make the validator run twice, but I think that's probably ok.

Attachments (1)

db_fields.diff (695 bytes) - added by amadison 5 years ago.

Download all attachments as: .zip

Change History (7)

Changed 5 years ago by amadison

comment:1 Changed 5 years ago by anonymous

  • Has patch set
  • milestone set to 1.3
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

it is really a bug

comment:2 Changed 5 years ago by Leo

+1 for a fix, ideally in a 1.2.x release.

We're running into this bug as well since upgrading to 1.2.

comment:3 Changed 5 years ago by john_scott

Closed #13744 as a duplicate of this ticket.

Note to self, search open tickets before debugging Django as you can be sure someone has already created a ticket with the exact same patch two months prior.

comment:4 Changed 5 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [13475]) Fixed #13613 -- Ensure that forms.URLField and forms.EmailField are used on a modelform. This ensures that fields are URL and Email fields are cleaned consistently when included on model forms. Thanks to amadison for the report.

comment:5 Changed 5 years ago by russellm

(In [13476]) [1.2.X] Fixed #13613 -- Ensure that forms.URLField and forms.EmailField are used on a modelform. This ensures that fields are URL and Email fields are cleaned consistently when included on model forms. Thanks to amadison for the report.

Backport of r13475 from trunk.

comment:6 Changed 4 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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