And:
use
table.customer.comment = A(_class="glyphicon glyphicon-plus-sign",
data={"toggle":"modal", "target":"#myModal"})
or
table.customer.comment = A(_class="glyphicon glyphicon-plus-sign",
**{"_data-toggle":"modal", "_data-target":"#myModal"})
T
he BOOK says:
Notice that helper attributes are passed as keyword arguments to the
helper. In some cases, however, attribute names include special characters
that are not allowed in Python identifiers (e.g., hyphens) and therefore
cannot be used as keyword argument names. For example:
DIV('text', _data-role='collapsible')
will not work because "_data-role" includes a hyphen, which will produce a
Python syntax error.
In such cases you have a couple of options. You can use the data argument
(this time without a leading underscore) to pass a dictionary of related
attributes without their leading hyphen, and the output will have the
desired combinations e.g.
>>> print DIV('text', data={'role': 'collapsible'})
<div data-role="collapsible">text</div>
or you can instead pass the attributes as a dictionary and make use of
Python's ** function arguments notation, which maps a dictionary of
(key:value) pairs into a set of keyword arguments:
>>> print DIV('text', **{'_data-role': 'collapsible'})
<div data-role="collapsible">text</div>
Regards, Martin
2015-06-19 4:30 GMT+02:00 Anthony <[email protected]>:
> Yes, the comment can be a helper, but yours is not a helper -- it is a
> lambda function, which is not allowed.
>
> Anthony
>
>
> On Thursday, June 18, 2015 at 6:52:08 PM UTC-4, 黄祥 wrote:
>>
>> hi,
>>
>> is it possible to have DAL comment with HTML helper?
>> *from book it said :*
>> comment is a string (or a *helper *or something that can be serialized
>> to a string) that contains a comment associated with this field, and will
>> be displayed to the right of the input field in the autogenerated forms.
>>
>> *code*
>> table.customer.comment = lambda customer, field: A(_class="glyphicon
>> glyphicon-plus-sign", _data-toggle="modal", _data-target="#myModal")
>>
>> *it return an error*
>> Traceback
>>
>> 1.
>> 2.
>> 3.
>> 4.
>> 5.
>> 6.
>> 7.
>> 8.
>> 9.
>>
>> Traceback (most recent call last):
>> File "C:\web2py\gluon\restricted.py", line 226, in restricted
>> ccode = compile2(code, layer)
>> File "C:\web2py\gluon\restricted.py", line 209, in compile2
>> return compile(code.rstrip().replace('\r\n', '\n') + '\n', layer, 'exec')
>> File "C:/web2py/applications/delivery/models/db_wizard_6_sale_order.py"
>> <https://127.0.0.1/admin/default/edit/delivery/models/db_wizard_6_sale_order.py>,
>> line 38
>> table.customer.comment = lambda customer, field: A(_class="glyphicon
>> glyphicon-plus-sign", _data-toggle="modal", _data-target="#myModal")
>> SyntaxError: keyword can't be an expression
>>
>>
>>
>> thanks and best regards,
>> stifan
>>
> --
> 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/d/optout.
>
--
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/d/optout.