Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Setting initial on multi select widget [RSS Feed]

#1 June 18, 2010 14:03:34

Jeff G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Setting initial on multi select widget


I have been trying unsuccessfully to select the initial value of a
multi select drop down.

I was wondering what I am missing as to why this does not seem to be
working.

Here is a snippet of my code

self.fields = forms.MultipleChoiceField(
choices=choicelist,
initial='choice753',
required=False)

Here is the value of my choicelist

choice list is

Any help would be greatly appreciated.

Thanks,
Jeff

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 June 18, 2010 14:44:53

bruno d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Setting initial on multi select widget


On 18 juin, 15:03, Jeff Green <jeffhg2...@gmail.com> wrote:
> I have been trying unsuccessfully to select the initial value of a
> multi select drop down.
>
> I was wondering what I am missing as to why this does not seem to be
> working.
>
> Here is a snippet of my code
>
> self.fields = forms.MultipleChoiceField(
>                                         choices=choicelist,
>                                         initial='choice753',
>                                         required=False)
>

A MultipleChoiceField works with a sequence, not with a single
element, so passing the appropriate sequence as initial value might
help.

self.fields = forms.MultipleChoiceField(
choices=choicelist,
initial=, # use
a list here
required=False)



PS 1 : not tested but IIRC that's how I always initialised these
fields.

PS 2 : In case you wonder why it didn't raise an exception with a
single string as initial value, remember that strings are sequences
too - so what the MultipleChoiceField tried to use was in fact !-)

HTH

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 June 18, 2010 15:13:29

Jeff G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Setting initial on multi select widget


Can you clarify what you mean by sequence. It would be appreciated if you
can provide me of an example which might help me to understand how to
implement it.

Thanks,
Jeff

On Fri, Jun 18, 2010 at 8:44 AM, bruno desthuilliers <
bruno.desthuilli...@gmail.com> wrote:

>
>
> On 18 juin, 15:03, Jeff Green <jeffhg2...@gmail.com> wrote:
> > I have been trying unsuccessfully to select the initial value of a
> > multi select drop down.
> >
> > I was wondering what I am missing as to why this does not seem to be
> > working.
> >
> > Here is a snippet of my code
> >
> > self.fields = forms.MultipleChoiceField(
> > choices=choicelist,
> > initial='choice753',
> > required=False)
> >
>
> A MultipleChoiceField works with a sequence, not with a single
> element, so passing the appropriate sequence as initial value might
> help.
>
> self.fields = forms.MultipleChoiceField(
> choices=choicelist,
> initial=, # use
> a list here
> required=False)
>
>
>
> PS 1 : not tested but IIRC that's how I always initialised these
> fields.
>
> PS 2 : In case you wonder why it didn't raise an exception with a
> single string as initial value, remember that strings are sequences
> too - so what the MultipleChoiceField tried to use was in fact !-)
>
> HTH
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 June 18, 2010 15:22:24

Tom E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Setting initial on multi select widget


Another example, on top of the example he put in his original post?

A sequence is a generic python term for a collection of objects that
can be iterated through. So a list (or array, if you don't grok the
lingo) is a sequence, so is a tuple, so is a string - its a sequence
of characters.

All these things are sequences:


( 'a', 'b', 'c', )
'abc'

and they all have identical output in the following code:

for obj in seq:
print obj

In your question, you were passing the string 'choice753' as the
initial value for your multi select widget. Multi select widgets want
a sequence as an initial value, with each value in the sequence
corresponding to a selected element (so you were saying 'the selected
elements are those with values 'c', 'h', 'o', 'i', 'c', 'e', '7', '5'
or '3'). You should have been passing a sequence of selected choices,
so either or ( 'choice753', ) (note the trailing
commas).

If you look closely at Bruno's reply, this is exactly what he told you.

Cheers

Tom

On Fri, Jun 18, 2010 at 3:13 PM, Jeff Green <jeffhg2...@gmail.com> wrote:
> Can you clarify what you mean by sequence. It would be appreciated if you
> can provide me of an example which might help me to understand how to
> implement it.
>
> Thanks,
> Jeff
>
> On Fri, Jun 18, 2010 at 8:44 AM, bruno desthuilliers
> <bruno.desthuilli...@gmail.com> wrote:
>>
>>
>> On 18 juin, 15:03, Jeff Green <jeffhg2...@gmail.com> wrote:
>> > I have been trying unsuccessfully to select the initial value of a
>> > multi select drop down.
>> >
>> > I was wondering what I am missing as to why this does not seem to be
>> > working.
>> >
>> > Here is a snippet of my code
>> >
>> > self.fields = forms.MultipleChoiceField(
>> >                                         choices=choicelist,
>> >                                         initial='choice753',
>> >                                         required=False)
>> >
>>
>> A MultipleChoiceField works with a sequence, not with a single
>> element, so passing the appropriate sequence as initial value might
>> help.
>>
>> self.fields = forms.MultipleChoiceField(
>>                                          choices=choicelist,
>>                                          initial=, # use
>> a list here
>>                                          required=False)
>>
>>
>>
>> PS 1 : not tested but IIRC that's how I always initialised these
>> fields.
>>
>> PS 2 : In case you wonder why it didn't raise an exception with a
>> single string as initial value, remember that strings are sequences
>> too - so what the MultipleChoiceField tried to use was in fact !-)
>>
>> HTH
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>>http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Setting initial on multi select widget [RSS Feed]

Board footer

Moderator control

Enjoy the 18th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support