The desired outcome is an input field filled with a default value that
is removed when the field is focused.
For example, having the value "Search" in an input box that disappears
upon focus.
The deform mask functionality may make this scenario possible, however
this is not really a mask at all.
So I thought maybe a good course of action would be to write a custom
serialize/deserialize widget.
Please let me know if this is a good idea or if I am recreating the
wheel.
One slight problem I had with this solution is that my serialize
function sets the css_class attribute even when it is not supposed to.
You can see the comments below. The only reason I bring it up is
because it makes me questions whether I am misunderstanding a
fundamental element of the serialize method. The 'ui-placeholder'
class is needed to make the text a light gray color.
class CheckPlaceholder(TextAreaWidget):
def serialize(self, field, cstruct, readonly=False):
if cstruct is null:
cstruct = field.widget.placeholder
field.widget.css_class = 'ui-placeholder'
# sets the css_class above even if the value is not null.
Maybe its using a cached template?
# so i added this extra if statement which clears the
css_class although this should not be necessary
if cstruct != field.widget.placeholder:
field.widget.css_class = ''
template = readonly and self.readonly_template or
self.template
return field.renderer(template, field=field, cstruct=cstruct)
def deserialize(self, field, pstruct):
if pstruct is null or pstruct == field.widget.placeholder:
return null
if self.strip:
pstruct = pstruct.strip()
if not pstruct:
return null
return pstruct
class Schema(MappingSchema):
product = SchemaNode(
String(),
widget = CheckPlaceholder(placeholder='example: \r\nkitchen
sink with dimensions'))
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en.