I created this ticked today, and it got closed with a wontfix flag, but I 
still think it would be a good idea to implement:
https://code.djangoproject.com/ticket/29912

The reason why it got closed is that django shouldn't modify the input like 
that, but the link which is mentioned in the response talks about stripping 
spaces from beginning and end of values, which was resigned some time ago, 
but It's now a part of django. All form fields automatically strip spaces 
from beginning and end after submission. It's even the default behaviour, 
although it's optional.

The next thing that is mentioned in the reply, is that the input may come 
from an API. I understand this change would be backwards incompatible, it 
it's turned on by default, but there's no problem in managing this. There 
could be a flag for it on django.forms.fields.CharField, and ModelForm 
could automatically enable/disable it the same as it assigns the TextInput 
/ Textarea widget. It seems right to me to differentiate between single 
line / multiline fields. I was thinking on how to resolve this issue today, 
and as I have 23 forms in my project, it seemed error-prone to do it in 
Form.clean_xxx, in so many places.

As a temporary solution, I implemented it for django.forms.widgets.Input by 
overriding value_from_datadict (monkey patch, which i would definitely like 
to remove in the future).

>From the logical standpoint, it seems relevant to me to implement such a 
functionality for <input> fields. From my point of view, the main 
difference between an <input> and a <textarea> is that input is just for 
one-line values, whereas a textarea is used when you need a multiline input 
from the user. Even web browsers have this restriction, and I think it 
would be a bit safer and more consistent. It took me a while to realise 
that I should remove newlines for all my input fields. Maybe it's not even 
such a bad idea to implement it in the widgets, as I'm thinking about it. 
It would be a lot easier, and maybe it's even the right place for it.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/ad1ebc6f-f935-49b2-9ce5-c97b0d5835a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to