On Sunday, 29 September 2013 22:58:38 UTC+1, Marcin Szamotulski wrote:
-- Dear Django users,
The short question is: How to use Textarea widget with initial value?
The long version: I have a form with a simple Textarea widget
class Form(forms.Form):
f = forms.CharField(widget=forms.Textarea())
in a view I set an initial value:
form = Form(initial={'f': 'initial value})
and it renders on a page as
<textarea>intial value</textarea>
Then let say I modify the initial value to 'new value'
Then when I POST the form (i.e. send a POST request). The
request.POST.getlist('f')
returns
['new value', 'intial value']
and since the 'initial value' is after the 'new value' when I intialise
the form
form = Form(request.POST)
it has form.cleaned_data['f'] == 'initial value'.
What is the correct way to make initial value in a textarea so that it
is not submitted with the form.
Playing with this I tried to remove the 'initial value' using javascript
($('textarea[name="f"]).html('')), but the submitted date (request.POST)
was not affected.
Thanks for help,
Marcin
How are you "modifying the initial value to 'new value' "? If you're simply typing in the field to replace the text that's there, there's no way that request.POST can contain the original data. You seem to be doing something odd somewhere.
--
DR.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aeb5643b-5e8b-4fa7-9867-d80a38307d6c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment