Re: input data will be lost if there are errors in the form
Thank you, Tom. It's exactly what I need. On Thu, May 30, 2013 at 3:55 AM, Tom Evans wrote: > On Thu, May 30, 2013 at 3:31 AM, Jeff Hsu wrote: > > Hi, > > > > I find this very interesting. In my html template form: > > > > > enctype="multipart/form-data"> > > {% csrf_token %} > > > > {{ form.title.errors}} > > > > {{form.title}} > > . > > This is fine, and it will show the previous inputs if there are errors in > > the form, however, if I try to customize the html input field, for > example, > > as below, instead of using automatic generated {{form.title}} > >> placeholder="Question Title" name="title" cols="50" rows="1"> > > > > The previous inputs will be lost if there are errors in the form. Does > > anybody know why? I need some direction and explanation for this. Thank > > you > > > > Jeff > > If you output the fields yourself, you are responsible for ensuring > that the value, name, id - everything, in fact - is correct. In this > case, when you are outputting your textarea manually, you are omitting > the value, either from the initial value passed in, or from the > submitted data when redisplaying a bound form that has errors. > > So, you can either do all that work yourself for each field, or you > can allow django to display the field, and manipulate django so that > it creates your HTML as you like it. For instance, you can pass > additional attributes to the widget used to render the field, read > more about widgets in the docs: > > https://docs.djangoproject.com/en/1.5/ref/forms/widgets/ > > Cheers > > Tom > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Django users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/django-users/2BMKRHHPj38/unsubscribe?hl=en > . > To unsubscribe from this group and all its topics, send an email to > django-users+unsubscr...@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?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- 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+unsubscr...@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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: input data will be lost if there are errors in the form
On Thu, May 30, 2013 at 3:31 AM, Jeff Hsu wrote: > Hi, > > I find this very interesting. In my html template form: > > enctype="multipart/form-data"> > {% csrf_token %} > > {{ form.title.errors}} > > {{form.title}} > . > This is fine, and it will show the previous inputs if there are errors in > the form, however, if I try to customize the html input field, for example, > as below, instead of using automatic generated {{form.title}} >placeholder="Question Title" name="title" cols="50" rows="1"> > > The previous inputs will be lost if there are errors in the form. Does > anybody know why? I need some direction and explanation for this. Thank > you > > Jeff If you output the fields yourself, you are responsible for ensuring that the value, name, id - everything, in fact - is correct. In this case, when you are outputting your textarea manually, you are omitting the value, either from the initial value passed in, or from the submitted data when redisplaying a bound form that has errors. So, you can either do all that work yourself for each field, or you can allow django to display the field, and manipulate django so that it creates your HTML as you like it. For instance, you can pass additional attributes to the widget used to render the field, read more about widgets in the docs: https://docs.djangoproject.com/en/1.5/ref/forms/widgets/ Cheers Tom -- 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+unsubscr...@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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
input data will be lost if there are errors in the form
Hi, I find this very interesting. In my html template form: {% csrf_token %} {{ form.title.errors}} *{{form.title}}* . This is fine, and it will show the previous inputs if there are errors in the form, however, if I try to customize the html input field, for example, as below, instead of using automatic generated {{form.title}} * * The previous inputs will be lost if there are errors in the form. Does anybody know why? I need some direction and explanation for this. Thank you Jeff -- 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+unsubscr...@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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.