>
> ok, say i have an INPUT like:

> INPUT(_name="dude", _type="text", _id="dude_int")
>
> how can i remove the name attribute from the tag?
>

form.element('[name=dude]').attributes.pop('_name')

or

del form.element('[name=dude]')['_name']

The attributes of an HTML helper act like a dictionary, and they are in 
fact stored in the .attributes attribute, which is a dictionary. So, you 
can do any dictionary operations on .attributes (e.g., .pop). You can also 
do some dictionary operations on the helper itself (without going through 
.attributes), including accessing values via keys and using the .update 
method.
 

> also, say i want to add a non-standard attribute to the tag like:
>
> form.element(_id="dude_int").update(_custom_attr1="attr1_data")
>
> will web2py complain or except or error if i try to add a non-HTML 
> standard attribute to a tag?  if so, how can i get around that?
>

No, it won't complain, though because the attribute is specified as a 
keyword argument, it must be a legal Python identifier when using the above 
syntax. Otherwise, you can use the alternative method for passing keyword 
arguments:

form.element(_id='dude_int').update(**{'_custom-attr-with-hyphens': 
'attr_data'})

If it is specifically a "data-" attribute, you can now also do:

form.element(_id='dude_int').update(data=dict(custom='attr_data'))

which will result in a "data-custom" attribute being added.

Anthony

-- 

--- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to