简体   繁体   中英

How to add onfocus to a z3c.form input

I am developing a site in plone and am currently writing a form using python and z3c.forms

Currently I am using an interface to define form fields like...

class IMyInterface(Interface):

    name = schema.TextLine(
            title=_(u"Name"),
            default=_(u"Name")
        )

and then assigning to fields like...

fields = field.Fields(IMyInterface)

this is then rendered in a template using tal like...

<div tal:replace="structure python: view.contents" />

I would like to render an onfocus attribute within the markup of the input. Is there a way to do this?

You can give arbitrary HTML attribute parameters to z3c.form widgets in updateWidgets() phase of your form.

http://collective-docs.readthedocs.org/en/latest/forms/z3c.form.html#modifying-a-widget

HTML attributes for widgets:

http://svn.zope.org/z3c.form/trunk/src/z3c/form/browser/widget.py?rev=103729&view=auto

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM