how to add a style to form tags

216 views
Skip to first unread message

arche...@gmail.com

unread,
Oct 28, 2013, 5:00:20 PM10/28/13
to web...@googlegroups.com

I was wondering how to put a style on a form tag.
{{login_form.custom.begin['_style']="display:inline"}} fails with error <type 'exceptions.TypeError'>('XML' object does not support item assignment)

Thank you in advance!

Niphlod

unread,
Oct 28, 2013, 5:57:08 PM10/28/13
to web...@googlegroups.com
form.custom.begin is not an helper like A, LI, FORM, etc... so you can't use usual _attributes for it.

form.custom.begin just carries <form ......> ... that's because you're supposed to fill in between all your form widgets and then close it with form.custom.end, that in turn just carries the ending </form> piece.

António Ramos

unread,
Oct 28, 2013, 5:56:45 PM10/28/13
to web...@googlegroups.com
maybe in your controller...


 form.element(_name='email')['_class'] = "campo_email"
    form.element(_name='first_name')['_class'] = "campo_nome"
    form.element(_name='last_name')['_class'] = "campo_sobrenome"
    form.element(_name='password')['_class'] = "campo_senha"
    form.element(_name='password_two')['_class'] = "campo_confirmacao"


2013/10/28 <arche...@gmail.com>

I was wondering how to put a style on a form tag.
{{login_form.custom.begin['_style']="display:inline"}} fails with error <type 'exceptions.TypeError'>('XML' object does not support item assignment)

Thank you in advance!

--
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 the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

arche...@gmail.com

unread,
Oct 28, 2013, 6:02:31 PM10/28/13
to web...@googlegroups.com
I actually wanted to append the style to the form tag itself, not its elements. So like <form style='display:inline'>
What I am getting is that this isn't possible?

António Ramos

unread,
Oct 28, 2013, 6:05:36 PM10/28/13
to web...@googlegroups.com
if i understand you , use css in your view to acomplish that

form {
...
}


2013/10/28 <arche...@gmail.com>

Paolo Caruccio

unread,
Oct 28, 2013, 6:12:28 PM10/28/13
to web...@googlegroups.com
Perhaps this still works


Replace 

form['_class'] = "form-horizontal"

with

form['_style'] = "display:inline;"
Message has been deleted

arche...@gmail.com

unread,
Oct 28, 2013, 6:20:42 PM10/28/13
to web...@googlegroups.com
{{login_form['_style']="display:inline"}} does not work

@Ramos, in this specific case, I would like the style to be inline with the form tag rather than anywhere else, since anywhere else would affect forms globally.

António Ramos

unread,
Oct 28, 2013, 6:42:13 PM10/28/13
to web...@googlegroups.com
@css

form.myform {
...
}

only afects myform class, not all forms


2013/10/28 <arche...@gmail.com>

arche...@gmail.com

unread,
Oct 28, 2013, 6:48:26 PM10/28/13
to web...@googlegroups.com
Part of what I wanted to do was manipulate the inline style dynamically inline in the tag. It seems that it is being stated that a workaround is needed for this... but thank you for all your help!

Anthony

unread,
Oct 28, 2013, 7:34:53 PM10/28/13
to web...@googlegroups.com
How are you creating the form? Is it the auth.login() form, or your own form? Do you need to use form.custom.begin to get the layout you need?

arche...@gmail.com

unread,
Oct 29, 2013, 10:12:37 AM10/29/13
to web...@googlegroups.com
What I ended up doing was just that; I wrote out what form.custom.begin was outputting and added the style tag manually. I was just wondering if there was a way to manipulate the tag without resorting to this.

Anthony

unread,
Oct 29, 2013, 10:44:23 AM10/29/13
to web...@googlegroups.com
On Tuesday, October 29, 2013 10:12:37 AM UTC-4, arche...@gmail.com wrote:
What I ended up doing was just that; I wrote out what form.custom.begin was outputting and added the style tag manually. I was just wondering if there was a way to manipulate the tag without resorting to this.

It depends on how the form is created. If you create it directly, you can just do:

form = SQLFORM(..., _style='...')

If it's an Auth form, you can't do that, but if you don't specifically need to use the form.custom items to create a custom layout, you can do:

form = auth.login()
form
['_style'] = ...

If it's an Auth form and you need to use form.custom.begin, then the best option is probably what you have done. Anway, doing:

<form action="#" enctype="multipart/form-data" method="post" style="...">

isn't much more difficult than doing:

{{form.custom.begin['_style'] = '...'}}
{{=form.custom.begin}}

I suppose another option would be:

{{=str(form.custom.begin).replace('>', ' style="...">')}}

Though just typing out the raw HTML is just as easy and probably more straightforward.

Anthony
Reply all
Reply to author
Forward
0 new messages