text field remove default when user inputs data

33 views
Skip to first unread message

thodoris

unread,
Nov 16, 2011, 4:24:54 AM11/16/11
to web2py-users
Hello,

I have a text field in my db with a default instructive text like
"Enter your comment here", but i would like when the user tries to
input text, the default text to disappear without having to delete it
manually

Anthony

unread,
Nov 16, 2011, 4:42:31 AM11/16/11
to web...@googlegroups.com
You can use a comment instead of a default:

    Fields(..., comment='Enter your comment here')

though that will display next to or below the input field (depending on your formstyle) rather than in the text box itself.

As an alternative, you can set the HTML5 'placeholder' attribute for the input field by customizing the field's widget:

    Field(...,
        widget=lambda f,v: SQLFORM.widgets.text.widget(f, v, _placeholder='Enter your comment here'))

Anthony

thodoris

unread,
Nov 16, 2011, 5:04:05 AM11/16/11
to web2py-users
Thnx a lot!

Ron Chatterjee

unread,
Feb 5, 2016, 3:15:27 PM2/5/16
to web2py-users
Is there a similar widget that works for the string?

Because when I do the following, it doesn't work


Field(...,
        widget=lambda f,v: SQLFORM.widgets.string.widget(f, v, _placeholder='Enter your comment here'))

Anthony

unread,
Feb 5, 2016, 3:32:02 PM2/5/16
to web2py-users
Works for me. Must be a problem somewhere else in your code.

Ron Chatterjee

unread,
Feb 5, 2016, 3:45:38 PM2/5/16
to web2py-users
You are right. I forgot to mention, I was trying to work it with 'list:string'

And it breaks the list. 
Reply all
Reply to author
Forward
0 new messages