add_button is a method of FORM(). But I'm not sure it works as the
following shows:
cjk@debian:~/pybin/web2py-src/web2py$ python
Python 2.7.3 (default, Jan 2 2013, 13:56:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from gluon import html
>>> simpleform = html.FORM(html.INPUT(_type="text", _name="mytext"))
>>> simpleform.xml()
'<form action="#" enctype="multipart/form-data" method="post"><input
name="mytext" type="text" /></form>'
>>> # Now comes an exception
...
>>> simpleform.add_button('foo', html.URL('bar', 'baz', 'foo'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "gluon/html.py", line 2216, in add_button
submit.parent.append(
AttributeError: 'NoneType' object has no attribute 'parent'
>>>
>>> # Now we fix the exception
...
>>> simpleform.append(html.INPUT(_type='submit'))
>>> simpleform.xml()
'<form action="#" enctype="multipart/form-data" method="post"><input
name="mytext" type="text" /><input type="submit" /></form>'
>>>
>>> # Now add_button will appear to work
...
>>> simpleform.add_button('foo', html.URL('bar', 'baz', 'foo'))
>>>
>>> #See, no exception. But look at this:
...
>>> simpleform.xml()
'<form action="#" enctype="multipart/form-data" method="post"><input
name="mytext" type="text" /><input type="submit" /></form>'
>>>
>>> #Whiskey Tango Fox? Button doesn't seem to be there
On Wednesday, September 25, 2013 1:17:37 PM UTC-4, wb wrote:
>
> Trying to generate a small form that is all buttons:
>
> def month-example:
> months = {'January', 'February', 'March'}
>
> form = FORM()
> for month in months:
> # this fails
> form.add_button(month, URL(month))
> return dict(form=form)
>
> This generates 'NoneType' object has no attribute 'parent'.
>
> Creating links with helpers works:
>
> form += A( month, _href=URL(month) )
>
> But the form is a dictionary, and the months are out of order. I think
> that add_button preserves the order, but have not verified that.
>
> Does add_button only work with SQLFORM?
>
> How can the order of elements added to a form programmatically be
> controlled?
>
--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.