Hi Eric,

I'm just starting with TG (2.1b2) and have gotten a basic form working
but I can't figure out if the SingleSelectField supports the
"selected" attribute.  I've snipped out some of my code (this is when
I was playing with attrs and container_attrs, neither of which
worked):

class ContactInfoForm(TableForm):
   states = webhelpers.constants.us_states()

   fields = [SingleSelectField('state', label_text = 'State:*  ',
options = states, container_attrs = {'selected':'CA'}, validator =
String())]

I'm trying to have the default be California when the form loads.


I think the proper thing to use is "default" here. Set that to whatever the key of your option is ("CA" in your case most probably)

However, there are two other options here:

- if the form is displayed, pass a value to the single-select-field that corresponds to one of the options. This is mainly used for pre- population with existing values.

 - pass a attrs-dictionary as one of the options.

I summarized all the various possibilities in the script at the end of this post.



A couple of other related questions...  Is it considered appropriate
to cross post something like this to the TW group as well?  I started
here since TG is the highest level and I'm not sure yet of all the
interactions.  Also, if "selected" is supported, how should I have
figured it out?  I looked at some of the source files using the Trac
interface on the TW site but wasn't able to puzzle it out (relatively
new to Python too); I did look at the TW site docs...


It's a shame that the tw.forms-docs don't comment on the SingleSelectField. I will try & enhance that ASAP, it might take a while though.

Other than that, it's perfectly fine to ask questions here. I'm reading both lists :) It is part of the way TG is created that the information is spreaded, and sometimes requires you to ask on different MLs. While this is somewhat annoying sometimes, it has also the benefit of a dedicated community for e.g. SQLAlchemy which has a much broader scope.

But again, first asking here is fine.



Thanks for your time,
Eric
PS It would be nice if somebody could get Elixir back in sync with TG


We use it - it is really simple to set up. Just not via build-in qickstart templates. But all you essentially need to do is to copy a boiler-plate elixir setup into the generated model files.

Diez

The script:


from tw.forms import *


ssf = SingleSelectField("foo", options=["foo", "bar", "baz"], default="bar")

print ssf.render()


form = TableForm("form", fields=[ssf], action="")

print form.render(dict(foo="baz"))

ssf = SingleSelectField("foo", options=["foo", "bar", "baz", ("padamm", "padamm", dict(selected="selected"))])

print ssf.render()


--
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to