How to add CSS classes to auth.login custom?

209 views
Skip to first unread message

Chris

unread,
Feb 27, 2013, 4:20:26 PM2/27/13
to web...@googlegroups.com
Hello,

I have a form that looks like this:
            {{top_login_form = auth.login(next = page_currentPath_get(request))}}
            {{top_login_form.elements('form')[0]['_class'] = 'login_form'}}
            {{=top_login_form.custom.begin}}

Trouble is, auth.login calls SQLFORM and sets custom.begin before the '_class' attribute takes effect, and auth.login doesn't take custom attributes. It seems like the long term solution might be to have custom.begin be a method - in the meantime I'm probably going to overwrite custom.begin myself. Any suggestions?

Thanks!

Niphlod

unread,
Feb 27, 2013, 4:25:16 PM2/27/13
to web...@googlegroups.com
your own template instead of the standard one defined in views/default/user.html ?

Chris

unread,
Feb 27, 2013, 4:45:43 PM2/27/13
to web...@googlegroups.com
This is an override of auth.login, which is being used in multiple pages, not just views/default/user.html. Auth.login already did a lot of things with custom CSS classes that I'd like to keep using. At the moment I'm doing the following:


                    {{top_login_form = auth.login(next = page_currentPath_get(request))}}
                    {{
                    top_login_form.elements('form')[0]['_class'] = 'login_form'
                    (begin, end) = top_login_form._xml()
                    top_login_form.custom.begin = XML("<%s %s>" % (top_login_form.tag, begin))
                    }}
                    {{=top_login_form.custom.begin}}

H. Das

unread,
Apr 18, 2014, 12:27:46 PM4/18/14
to web...@googlegroups.com
Use jQuery:

<script>
     $('form').attr({"class":"my-class"});
</script>

Christopher L

unread,
Apr 18, 2014, 1:10:28 PM4/18/14
to web...@googlegroups.com
That could work. Seems a bit uncouth, not to mention if jQuery isn't loaded that class wouldn't be added, and also that this would attach that class to every form on the page. I could hack around those things but it would be just that - a hack - and I'd prefer to do things in a robust manner.


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)

---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/W1ErCdPrcIE/unsubscribe.

To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Adventure Cow: Facebook | Twitter

Paolo Caruccio

unread,
Apr 18, 2014, 2:07:12 PM4/18/14
to web...@googlegroups.com

Christopher L

unread,
Apr 18, 2014, 2:10:55 PM4/18/14
to web...@googlegroups.com
Indeed, that answers my question.

It's been a long time since I was working on this, but it seems that in general, the web2py form shortcuts only go partway. If you are doing one of the things they support, everything works great, but once you go past that, you can't really "break out" and continue to use the forms while changing one thing or another - you have to instead remove everything and start from scratch.

Anthony

unread,
Apr 18, 2014, 4:55:09 PM4/18/14
to web...@googlegroups.com
It's been a long time since I was working on this, but it seems that in general, the web2py form shortcuts only go partway. If you are doing one of the things they support, everything works great, but once you go past that, you can't really "break out" and continue to use the forms while changing one thing or another - you have to instead remove everything and start from scratch.

What are some examples, other than form.custom.begin? 

Christopher L

unread,
Apr 18, 2014, 5:18:40 PM4/18/14
to web...@googlegroups.com
I'll leave this to someone who's played with it more recently, since it's been maybe a year since I looked...


On Fri, Apr 18, 2014 at 4:55 PM, Anthony <abas...@gmail.com> wrote:
It's been a long time since I was working on this, but it seems that in general, the web2py form shortcuts only go partway. If you are doing one of the things they support, everything works great, but once you go past that, you can't really "break out" and continue to use the forms while changing one thing or another - you have to instead remove everything and start from scratch.

What are some examples, other than form.custom.begin? 

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/W1ErCdPrcIE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages