You probably only want to clear it if it's value is the default so:

def text_widget(f,v):
    inp = SQLFORM.widgets.text.widget(f,v)
    inp['_onfocus'] = "if(this.value == '%s'){this.value = '';}" %
f.default
    return inp

On Dec 21, 9:22 am, "mr.freeze" <nat...@freezable.com> wrote:
> Here is an example widget that should do what you want:
>
> def text_widget(f,v):
>     inp = SQLFORM.widgets.text.widget(f,v)
>     inp['_onfocus'] = "jQuery(this).val('');"
>     return inp
>
> This is how you would use it:
>
> form = SQLFORM.factory(Field('mytext',
>                                  'text',default='Enter a value',
>                                  widget=text_widget))
>
> Hope that helps.
>
> On Dec 21, 7:09 am, weheh <richard_gor...@verizon.net> wrote:
>
> > I have a textarea with some welcoming text already in it, but I'd like
> > a javascript to clear the text with when the user sets focus on the
> > textarea. The textarea and the rest of my form, of which textarea is a
> > part, are created using a custom form that also uses widgets to
> > display the form fields. I think I need a custom widget to do what I
> > want. I've read the doc but just can't seem to make it work for me.
> > I'd appreciate it if someone could show me how to do it. Thx.

--

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


Reply via email to