#30077 closed New feature (invalid)
TextField constructor needs a strip=False option
| Reported by: | Rob van der Linde | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 2.1 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
In Django 1.9 an option strip=True was added to CharField, this is fine but it also seems to affect TextField and there is no way to pass a strip=False option to TextField constructor to turn that off.
The issue seems to be the formfield method, this has lead to people subclassing TextField to "fix" this addition to Django 1.9, for example:
class NonStrippingTextField(TextField):
"""A TextField that does not strip whitespace at the beginning/end of
it's value. Might be important for markup/code."""
def formfield(self, **kwargs):
kwargs['strip'] = False
return super(NonStrippingTextField, self).formfield(**kwargs)
Other people fix it in the form and override the admin form, this has become a bit messy, it seems to be necessary to introduce a strip argument to the TextField constructor, to avoid having to create custom field types.
Change History (3)
comment:1 by , 7 years ago
| Type: | Uncategorized → New feature |
|---|
comment:2 by , 7 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
comment:3 by , 7 years ago
Ah I see, I'll have to find a Wagtail specific fix, though I must say I do find this feature added to Django 1.9 extremely annoying.
Just to make it clear the
strip=Trueoption was added toforms.CharFieldand notdb.CharFieldlike the report seems to imply. Moving this option to the database layer has been discussed and rejected when the option was added to the form layer so I doubt there's consensus on adding an option to specializeTextFieldhere given striping spaces should be the desired behaviour in most cases just like withdb.CharField.Can't this be simply done with formfield_overrides or
formfield_for_dbfield?