Michele Cella wrote:
>
> I'm not even sure we need to remove ignore_key_missing since I've
> noticed (with some quick tests) that without this the validator can't
> say anything and it's totally by passed.
>
> What we need is probably a small additional logic in ForEach, I'm going
> to look at it when I get home...
>

Ok, it turns out that we can provide a default value for any missing
key by using:

     if_key_missing

removing ignore_key_missing from our Schema and using:

     if_key_missing = ''

will provide a value '' for every missing key, this works if we use a
ForEach validator for our multiple selection field like this:

     d = ForEach(v.Int(), if_missing = NoDefault)

This is also a good behavior IMHO, since it provides almost the same
solution I proposed in the Nested filter without bad hacks.

disabled_fields will still work but only if you're disabling not
required fields, this as suggested by Kevin still makes sense since you
wouldn't disable a required field normally otherwise this field is not
required, right? :D

One side effect of using if_key_missing in this way is that you always
get a dictionary containing a validated value for every key, for
example:

class Prova(Schema):
    if_key_missing = ''
    name = v.String()
    age = v.String()

with

to_python({})

gives:

{'age': '', 'name': ''}

this is how a normal TextField works since you always get '' in input,
and this is how a CheckBox unfortunately doesn't work but we can make
it work like this. ;-)

Now there is a small problem since our Schema ATM always contain the
validator for the submit button you end up to receive the submit button
value into it, we can solve this problem easily (and I already talked
with Alberto about this) by adding a field to a schema only and only if
is_named = True (this also makes a lot of sense IMHO), the is named
parameter is correctly handled by the init method of the Widget base
class and by the WidgetsList but will not work if you do something
like:

widget = Widget()
widget.name = ''

should we make name a Widget property? will this work in case of
inheritance if someone is setting name?

Ciao
Michele


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" 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-trunk
-~----------~----~----~----~------~----~------~--~---

Reply via email to