On Jan 8, 2008 9:52 AM, Lukasz Szybalski <[EMAIL PROTECTED]> wrote:
> On Jan 8, 2008 8:45 AM, Glauco <[EMAIL PROTECTED]> wrote:
> >
> >
> > > Pass it like this?
> > > XXXNo = widgets.TextField(validator=validators.Int(empty_value =
> > > lambda x: None))
> > >
> > > I still get xxxNo: 'null'
> > >
> > > Could you tell me what is the proper way of passing the empty_value to
> > > the walidator?
> > >
> > > Lucas
> > >
> > >
> >
> >
> > Hi Lucas, probably you are in this situation:
> > some js put a null value in your input field ---> string 'null'
> >
> > your validator can't see this as an empty value
> >
> >
> > 3 solutions :
> >
> > 1) (best) don't put in an integer field a 'null' value (null as string)
> >
> > 2) You must write your own validator, derivated from Int but 'null'
> > return None
> >
> > 3) You can validate your field as validator=validators.String after
> > that you can handle manually in your destination controller this field.
> >
> >
> > PS: that is the proper way to use empty value
>
> First: What would be the code to overload the validator.Int and
> include the empty_string =None?
> Second: Where would I put it? in controller.py?
So I finally figured that you test the empty kwargs from widget by doing:
if kwargs['LastName']:
#do some stuff on last name
It seems as the widget 'LastName' if empty sends empty string '' (good)
but when you have no expose template and your return kwargs it will
display 'null' (bad)
@expose()
def somefunction(self,**kwargs):
return dict(kwargs=kwargs)
Then you will see displayed:
{"tg_flash": null, "kwargs": {"LastName": "null }}
but if you set a template and return the filed to template the field
<a py:content="LastName">Name to be replaced</a> will display '' the
empty string.
It's really confusing, since I though that the widget return null but
in reality it was "return dict(kwargs=kwargs)" that displayed it
wrong.
So the question is: why does turbogears @expose() and return
dict(kwargs=kwargs) display "null" instead of '' in the browser?
Lucas
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---