FORM Generation Code.

75 views
Skip to first unread message

David J.

unread,
Dec 29, 2010, 1:52:52 PM12/29/10
to web...@googlegroups.com
Where is the code that Generates the FORMs?

What is the best way to modify this; Currently when it outputs the key name

It puts a colon; ex. "First Name:" instaead of just "First Name"

I simply want to remove that from the form.

Also on the links of the welcome app; That generate the "[ login |
register | lost pasword? ]" links

I want to remove all those extra chars.

I checked the templates I dont see it in there; I also see something in
gluon.tools.py but I dont want to modify gluon code.

Thanks.

Bruno Rocha

unread,
Dec 29, 2010, 2:02:07 PM12/29/10
to web...@googlegroups.com
you can set labels to auth_user table

db.auth_user.first_name.label = 'F Name'
db.auth_user.last_name.label = 'WHATEVER'

If you mean extra link in login/register form, simply edit /views/default/user.html



2010/12/29 David J. <da...@styleflare.com>

David J.

unread,
Dec 29, 2010, 2:15:58 PM12/29/10
to web...@googlegroups.com
Bruno;

That just changes the value; but the problem is the form code adds an extra ":" to the end of the name.

so if you do as you suggested. db.auth_user.first_name.label='FName'

It outputs "FName:" not "FName" without the trailing colon ":"


Thanks.

David J.

unread,
Dec 29, 2010, 2:21:15 PM12/29/10
to web...@googlegroups.com
Also if you look carefully this out put code is not consistent.

If you look at the "verify password" field it is not using class="w2p_fl|fw|fc"

Its just wrapped in a label.


Snippet from Register form.

<tr id="auth_user_password__row"><td class="w2p_fl"><label for="auth_user_password" id="auth_user_password__label">Password: </label></td><td class="w2p_fw"><input class="password" id="auth_user_password" name="password" type="password" value="" /></td><td class="w2p_fc"></td></tr><tr id="auth_user_password_two__row"><td><label>Verify Password:</label></td><td><input name="password_two" type="password" /></td><td>please input your password again</td></tr><tr id="submit_record__row"><td class="w2p_fl"></td><td class="w2p_fw"><input type="submit" value="Submit" /></td><td class="w2p_fc"></td></tr></table><div class="hidden"><input name="_next" type="hidden" value="/app/default/index" /><input name="_formkey" type="hidden" value="2854b30e-a066-47c4-a9e2-f6902b899e7c" /><input name="_formname" type="hidden" value="register" /></div></form>



On 12/29/10 2:02 PM, Bruno Rocha wrote:

Bruno Rocha

unread,
Dec 29, 2010, 2:30:10 PM12/29/10
to web...@googlegroups.com
2010/12/29 David J. <da...@styleflare.com>
Bruno;

That just changes the value; but the problem is the form code adds an extra ":" to the end of the name.

so if you do as you suggested. db.auth_user.first_name.label='FName'

It outputs "FName:" not "FName" without the trailing colon ":"



I am testing, trying a way to remove it, I guess if you pass labels to SQLFORM() the colon will be removed.

 

Ab...

unread,
Apr 25, 2011, 2:28:39 AM4/25/11
to web...@googlegroups.com
If there's a workaround other than modifying the core file, I'd like to know as I'm also facing the same issue.

Bruno Rocha

unread,
Apr 25, 2011, 10:06:41 AM4/25/11
to web...@googlegroups.com
On Mon, Apr 25, 2011 at 3:28 AM, Ab... <abhina...@radbox.me> wrote:
If there's a workaround other than modifying the core file, I'd like to know as I'm also facing the same issue.

You can pass your own labels, and the colon will be removed

formm = SQLFORM(db.yourtable, labels= dict(field1='My Field', field2='Other Field'), fields=['field1,'field2'])

Anthony

unread,
Apr 25, 2011, 10:55:18 AM4/25/11
to web...@googlegroups.com
If you want to use the default labels specified in the table definition, you can manually remove the colons from the labels via the server-side DOM (see http://web2py.com/book/default/chapter/05#Server-side-DOM-and-Parsing). Specifically, SQLFORM constructs each label as follows:
 
            label = LABEL(label, colon, _for=field_id,
                          _id=field_id+SQLFORM.ID_LABEL_SUFFIX)
 
 
The colon is the second component of the LABEL element, so you can remove all colons as follows:
 
    form=SQLFORM(db.yourtable)
    for label in form.elements('label'):
        label.components = label.components[-2]
 
 
Anthony

Ab...

unread,
Apr 26, 2011, 12:05:06 AM4/26/11
to web2py-users
How do I pass labels to auth forms ?

On Apr 25, 7:55 pm, Anthony <abasta...@gmail.com> wrote:
> If you want to use the default labels specified in the table definition, you
> can manually remove the colons from the labels via the server-side DOM (seehttp://web2py.com/book/default/chapter/05#Server-side-DOM-and-Parsing).

Bruno Rocha

unread,
Apr 26, 2011, 12:43:00 AM4/26/11
to web...@googlegroups.com
Not tested yet, but I guess you can do.

def user():
    db.auth_user.first_name.label = "Name Label"
    db.auth_user.last_name.label = "Family Name"
    return dict(form=Auth())



--
Bruno Rocha

Ab...

unread,
Apr 28, 2011, 2:08:10 AM4/28/11
to web2py-users
Thanks! but it still does not help with Change Password form fields
(old password, new password) - you can change them like
auth.messages.old_password = 'Old Password Some Text'
auth.messages.new_password = 'New Password Some Symbol'

But the colon still gets appended. IMHO, appending a colon should not
be the default behaviour for labels.

On Apr 26, 9:43 am, Bruno Rocha <rochacbr...@gmail.com> wrote:
> Not tested yet, but I guess you can do.
>
> def user():
>     db.auth_user.first_name.label = "Name Label"
>     db.auth_user.last_name.label = "Family Name"
>     return dict(form=Auth())
>
> --
> Bruno Rocha
> [ About me:http://zerp.ly/rochacbruno]
>
Reply all
Reply to author
Forward
0 new messages