Re: How to get selected value set in newforms
[EMAIL PROTECTED] skrev: > I think the problem is related to passing the resultsdict dictionary to the > DisplayForms. > Once, I did not pass in the dictionary then the initial value works. > Yes. Passing in values creates a bound form. Initial data are used only for unbound forms. I think the documentation is quite specific on that issue: """ The initial argument lets you specify the initial value to use when rendering this Field in an unbound Form. ... This is why initial values are only displayed for unbound forms. For bound forms, the HTML output will use the bound data. Also note that initial values are /not/ used as "fallback" data in validation if a particular field's value is not given. initial values are /only/ intended for initial form display: """ Nis --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to get selected value set in newforms
I think the problem is related to passing the resultsdict dictionary to the DisplayForms. Once, I did not pass in the dictionary then the initial value works. Jeff -- Original message -- From: [EMAIL PROTECTED] Nis, Thanks for the reply. I tried your example and that does not work. Here is the snippet of my code: views.py def displayresults(request, object_id): result = Result.objects.get(pk=object_id) startdatevalue = '' starttimevalue = '' startdatestr = '%s' % result.ExecutionStartDate if startdatestr != 'None': startdatevalue = "%04d-%02d-%02d" % ( result.ExecutionStartDate.year, result.ExecutionStartDate.month, result.ExecutionStartDate.day) starttimevalue = "%02d:%02d:%02d" % ( result.ExecutionStartDate.hour, result.ExecutionStartDate.minute, result.ExecutionStartDate.second) result_dict = {'TestName': result.TestName, 'TestVersion': result.TestVersion, 'ExecutionStartDate_date': startdatevalue, 'ExecutionStartDate_time': starttimevalue, 'SubmitDate': result.SubmitDate, 'ExecutionTime': result.ExecutionTime, 'Owner': result.Owner, 'Project': result.ProjectId, 'Phase': result.PhaseId, 'Testtype': result.TestTypeId, 'Station': result.StationId, 'UserIntervention': result.UserInt erventionFlag, } form = DisplayResults(result_dict) resultforms.py: class DisplayResults(forms.Form): TestName = forms.CharField() TestVersion = forms.CharField() ExecutionStartDate_date = forms.DateField() ExecutionStartDate_time = forms.TimeField() SubmitDate = forms.CharField() ExecutionTime = forms.CharField() Owner = forms.CharField() Project = forms.CharField() Phase = forms.CharField() Testtype = forms.CharField() status = forms.ChoiceField(required=False,choices =(('choice1','Choice1'),('choice2','Choice 2')), initial = 'choice2' ) Here is the html output: Status: Choice1 Choice 2 Jeff -- Original message -- From: Nis Jørgensen <[EMAIL PROTECTED]> > > [EMAIL PROTECTED] skrev: > > I am still having problems setting the select widget to the 3rd value in > > the > drop down list. > > Looking further it seems that the html does not have the > > selected="selected" > value in any of the items. > > The documentation states that if use a bound form you will see that in the > html. > > "initial" data are showed in an UNBOUND form. If the form is bound, it > shows the data you bound it to. This is clearly stated in the > documentation - I assume you mistyped here. > > > How would you go about getting the selected value in the html for a > choicefield. I tried the initial parameter in the choicefield and that does > not > change which value is selected. It always happens to be the first in the > list. > > > > Any help would greatly appreciated. > > For an unbound form, it works for me: > > """ > $ cat forms.py > from django import newforms as forms > > class SearchForm (forms.Form): > campaign = forms.ChoiceField(required=False,choices > =(('choice1','Choice1'),('choice2','Choice 2')), initial = 'choice2' ) > sf = SearchForm() > print sf > > $ python forms.py > Campaign:> name="campaign" id="id_campaign"> > Choice1 > Choice 2 > > """ > > Can you please > > a) Confirm that the above works for you > b) Post a self-contained example which shows your problem > > Nis > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to get selected value set in newforms
Nis, Thanks for the reply. I tried your example and that does not work. Here is the snippet of my code: views.py def displayresults(request, object_id): result = Result.objects.get(pk=object_id) startdatevalue = '' starttimevalue = '' startdatestr = '%s' % result.ExecutionStartDate if startdatestr != 'None': startdatevalue = "%04d-%02d-%02d" % ( result.ExecutionStartDate.year, result.ExecutionStartDate.month, result.ExecutionStartDate.day) starttimevalue = "%02d:%02d:%02d" % ( result.ExecutionStartDate.hour, result.ExecutionStartDate.minute, result.ExecutionStartDate.second) result_dict = {'TestName': result.TestName, 'TestVersion': result.TestVersion, 'ExecutionStartDate_date': startdatevalue, 'ExecutionStartDate_time': starttimevalue, 'SubmitDate': result.SubmitDate, 'ExecutionTime': result.ExecutionTime, 'Owner': result.Owner, 'Project': result.ProjectId, 'Phase': result.PhaseId, 'Testtype': result.TestTypeId, 'Station': result.StationId, 'UserIntervention': result.UserInterventionFlag, } form = DisplayResults(result_dict) resultforms.py: class DisplayResults(forms.Form): TestName = forms.CharField() TestVersion = forms.CharField() ExecutionStartDate_date = forms.DateField() ExecutionStartDate_time = forms.TimeField() SubmitDate = forms.CharField() ExecutionTime = forms.CharField() Owner = forms.CharField() Project = forms.CharField() Phase = forms.CharField() Testtype = forms.CharField() status = forms.ChoiceField(required=False,choices =(('choice1','Choice1'),('choice2','Choice 2')), initial = 'choice2' ) Here is the html output: Status: Choice1 Choice 2 Jeff -- Original message -- From: Nis Jørgensen <[EMAIL PROTECTED]> > > [EMAIL PROTECTED] skrev: > > I am still having problems setting the select widget to the 3rd value in > > the > drop down list. > > Looking further it seems that the html does not have the > > selected="selected" > value in any of the items. > > The documentation states that if use a bound form you will see that in the > html. > > "initial" data are showed in an UNBOUND form. If the form is bound, it > shows the data you bound it to. This is clearly stated in the > documentation - I assume you mistyped here. > > > How would you go about getting the selected value in the html for a > choicefield. I tried the initial parameter in the choicefield and that does > not > change which value is selected. It always happens to be the first in the > list. > > > > Any help would greatly appreciated. > > For an unbound form, it works for me: > > """ > $ cat forms.py > from django import newforms as forms > > class SearchForm (forms.Form): > campaign = forms.ChoiceField(required=False,choices > =(('choice1','Choice1'),('choice2','Choice 2')), initial = 'choice2' ) > sf = SearchForm() > print sf > > $ python forms.py > Campaign:> name="campaign" id="id_campaign"> > Choice1 > Choice 2 > > """ > > Can you please > > a) Confirm that the above works for you > b) Post a self-contained example which shows your problem > > Nis > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to get selected value set in newforms
[EMAIL PROTECTED] skrev: > I am still having problems setting the select widget to the 3rd value in the > drop down list. > Looking further it seems that the html does not have the selected="selected" > value in any of the items. > The documentation states that if use a bound form you will see that in the > html. "initial" data are showed in an UNBOUND form. If the form is bound, it shows the data you bound it to. This is clearly stated in the documentation - I assume you mistyped here. > How would you go about getting the selected value in the html for a > choicefield. I tried the initial parameter in the choicefield and that does > not change which value is selected. It always happens to be the first in the > list. > > Any help would greatly appreciated. For an unbound form, it works for me: """ $ cat forms.py from django import newforms as forms class SearchForm (forms.Form): campaign = forms.ChoiceField(required=False,choices =(('choice1','Choice1'),('choice2','Choice 2')), initial = 'choice2' ) sf = SearchForm() print sf $ python forms.py Campaign: Choice1 Choice 2 """ Can you please a) Confirm that the above works for you b) Post a self-contained example which shows your problem Nis --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to get selected value set in newforms
I am still having problems setting the select widget to the 3rd value in the drop down list. Looking further it seems that the html does not have the selected="selected" value in any of the items. The documentation states that if use a bound form you will see that in the html. How would you go about getting the selected value in the html for a choicefield. I tried the initial parameter in the choicefield and that does not change which value is selected. It always happens to be the first in the list. Any help would greatly appreciated. Thanks, Jeff -- Original message -- From: [EMAIL PROTECTED] I must be missing something here because when I change the statement to status = forms.ChoiceField(required=False, choices=statlist, initial="choice3") it still displays the 1st record in the list when I am trying to have the 3rd choice be the selected value. Jeff -- Original message -- From: Thomas Guettler <[EMAIL PROTECTED]> > > Am Mittwoch, 1. August 2007 15:58 schrieb jeffhg58: > > In newforms when I use the choicefield, I haven't been able to figure > > out how to set the value to say the third value in the drop down list. > > I tried setting the initial=3 but that did not seem to work. > > > > Here is the definition of the choicefield > > > > status = forms.ChoiceField(required=False, choices=statlist) > > Hi, > > if choices=(("a", "Letter A",) ... > > you set initial to "a". Simple, isn't it? > > Thomas > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to get selected value set in newforms
Hi, On 8/1/07, Thomas Guettler <[EMAIL PROTECTED]> wrote: > if choices=(("a", "Letter A",) ... > > you set initial to "a". Simple, isn't it? No, it isn't. It simply doesn't work with ModelMultipleChoiceField. > Thomas Kai --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to get selected value set in newforms
I must be missing something here because when I change the statement to status = forms.ChoiceField(required=False, choices=statlist, initial="choice3") it still displays the 1st record in the list when I am trying to have the 3rd choice be the selected value. Jeff -- Original message -- From: Thomas Guettler <[EMAIL PROTECTED]> > > Am Mittwoch, 1. August 2007 15:58 schrieb jeffhg58: > > In newforms when I use the choicefield, I haven't been able to figure > > out how to set the value to say the third value in the drop down list. > > I tried setting the initial=3 but that did not seem to work. > > > > Here is the definition of the choicefield > > > > status = forms.ChoiceField(required=False, choices=statlist) > > Hi, > > if choices=(("a", "Letter A",) ... > > you set initial to "a". Simple, isn't it? > > Thomas > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to get selected value set in newforms
Am Mittwoch, 1. August 2007 15:58 schrieb jeffhg58: > In newforms when I use the choicefield, I haven't been able to figure > out how to set the value to say the third value in the drop down list. > I tried setting the initial=3 but that did not seem to work. > > Here is the definition of the choicefield > > status = forms.ChoiceField(required=False, choices=statlist) Hi, if choices=(("a", "Letter A",) ... you set initial to "a". Simple, isn't it? Thomas --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---