form['_class'] = 'myclass'

or

form.update(_class='myclass')

A form is an HTML helper object, just like any other HTML helper, so the 
usual rules apply: 
http://web2py.com/books/default/chapter/29/05#HTML-helpers

Anthony

On Tuesday, December 18, 2012 11:33:32 PM UTC-5, Bhaskar Ramachandran wrote:
>
> As listed in the "view" code below, i am trying to customize the form 
> returned by auth.login(). Note that i have in my controller "return 
> dict(form=auth.login()). Then in the view code pasted below i am 
> customizing the login form.
> It seems to work fine except that i am unable to assign a class name to 
> this form. So my question is " How to set the class name for a form object 
> ?. There are posts in the mailing list to specify class name for elements 
> within the form object but i couldn't find one that explains how the class 
> name for the form object itself can be assinged. 
> Please let me know if my question needs more explanation. Thank you.
>               {{
>                     if not auth.is_logged_in() :
>                               if not 'register' in auth.settings.
> actions_disabled:
>                                    form.add_button(T('Register'),URL(args=
> 'register'),_class='btn')
>                                pass
>                                    if not 'request_reset_password' in auth
> .settings.actions_disabled:
>                                      form.add_button(T('Lost Password'),
> URL(args='request_reset_password'),_class='btn')
>                             pass 
>              }}
>         
>                     {{=form.custom.begin}}
>                        <a href=
> "/myscienceapp/default/register?_next=/default/index" style="margin-right: 
> 10px">Sign Up</a>
>                           <div class="input-append">
>                              <input id="user_username" 
> class="input-small" style="margin-right: 5px; border-radius: 5px 5px 5px 
> 5px;" type="text" name="email" placeholder="Email"/>
>                         <input id="user_password" class="input-small"style
> ="margin-right: 2px; border-radius: 5px 5px 5px 5px;" type="password" name
> ="password" placeholder="Password"/>
>                               <input class="btn btn-primary" 
> style="margin-right: 
> 5px; margin-bottom: 0px;border-radius: 5px 5px 5px 5px;" size="5" type=
> "submit" name="commit" value="Go!" />
>                                <input id="user_remember_me" 
> style="margin-right: 
> 5px; margin-bottom: 16px;" type="checkbox" name="remember" value="1" />
>                               <label class="string optional" 
> style="margin-right: 
> 10px;" for="user_remember_me">Remember me</label>
>                           <a href="/users/sign_up" style="margin-right: 
> 1px">Forgot?</a> 
>                          </div>
>                          {{=form.custom.end}}
>        <!--Using the command below,i am trying to set the class name for 
> the form.I was unable to do it both directly as well as using the parent() 
> method.. -->
>          {{form.element('div').parent['_class']='navbar-form pull-right 
> form-inline'}}
>         
>                 {{pass}}
>   
>
>

-- 



Reply via email to