there is no easy way to get a display widget if the form or field is not editable for the user<\/li>\n<\/ul>\nDefining a new schema field and registering the widget for this field seems a bit heavy, so I came up with providing a marker interface on the field:<\/p>\n
class IHaveSelectableKeywords(zope.interface.Interface):\r\n \"\"\"Marker interface to get a special keywords widget.\"\"\"\r\n\r\nclass IKeywords(zope.interface.Interface):\r\n keywords = zope.schema.List(\r\n title = _(\"Edit Keywords\"),\r\n value_type = zope.schema.Choice(\r\n vocabulary=u\"uc.keywords.Keywords\"))\r\n zope.interface.alsoProvides(keywords, IHaveSelectableKeywords)<\/pre>\nI registered the edit widget and display widget for the IHaveSelectableKeywords<\/code> interface, so the custom widget does not have to be set in the form like this (edit widget):<\/p>\n<adapter\r\n for=\".IHaveSelectableKeywords\r\n zope.publisher.interfaces.browser.IBrowserRequest\"\r\n provides=\"zope.app.form.browser.interfaces.ISimpleInputWidget\"\r\n factory=\".KWSelectWidgetFactory\"\r\n permission=\"zope.Public\" \/><\/pre>\n","protected":false},"excerpt":{"rendered":"zope.formlib\u00a0has the ability to customize the used widget like this: class KeywordsManagementForm(five.formlib.formbase.SubPageForm): form_fields = zope.formlib.form.Fields(IKeywords) form_fields[‘keywords’].custom_widget = KWSelectWidgetFactory I do not like this approach for two reasons: the widget has to be set manually\u00a0every time the specific field is used there is no easy way to get a display widget if the form or field … Continue reading “Custom widgets in zope.formlib”<\/span><\/a><\/p>\n","protected":false},"author":15344399,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[10221],"tags":[91109411,832,1368,72208,33810459],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pFP3y-2C","jetpack-related-posts":[{"id":349,"url":"https:\/\/blog.gocept.com\/2012\/12\/17\/yafowil-in-a-pyramid-project\/","url_meta":{"origin":162,"position":0},"title":"yafowil in a Pyramid project","author":"Michael Howitz","date":"December 17, 2012","format":false,"excerpt":"In a new Pyramid\u00a0project we used deform\u00a0to render forms. We did not really like it. (The reasons might be detailed in another post.) To see if other form libraries do better I\u00a0gave yafowil\u00a0a try at our\u00a0gocept Developer Punsch\u00a03: yafowil comes with written documentation. To get a form in our Pyramid\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":63,"url":"https:\/\/blog.gocept.com\/2011\/02\/04\/get-a-zc-sourcefactory-to-implement-an-interface\/","url_meta":{"origin":162,"position":1},"title":"Get a zc.sourcefactory to implement an interface","author":"","date":"February 4, 2011","format":false,"excerpt":"zc.sourcefactory is very handy to easily create a source (zope.schema.interfaces.IIterableSource to be precise) with corresponding titles and tokens for its contents. Every now and then a source requires an explicit interface. For zc.sourcefactory the following code snippet helps: class IMySource(zope.schema.interfaces.IIterableSource): \"\"\"my source\"\"\" class MySource( zc.sourcefactory.contextual.BasicContextualSourceFactory): \"\"\"The source factory.\"\"\" class source_class(\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1525,"url":"https:\/\/blog.gocept.com\/2015\/03\/06\/manage-javascript-dependencies-with-bowerstatic\/","url_meta":{"origin":162,"position":2},"title":"Manage JavaScript dependencies with BowerStatic","author":"","date":"March 6, 2015","format":false,"excerpt":"Last month I explained how to use Fanstatic to manage JS dependencies. Since we were more and more displeased by using Fanstatic, we recently switched to BowerStatic, the new kid on the block. Since the setup is a bit more complicated and you need more tools to have the same\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2789,"url":"https:\/\/blog.gocept.com\/2017\/10\/25\/testing-zope-4beta2\/","url_meta":{"origin":162,"position":3},"title":"Migrating from Zope 2.13 to 4.0b2","author":"Michael Howitz","date":"October 25, 2017","format":false,"excerpt":"Beta-Testing Zope 4 together with PerFact Innovation","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":12,"url":"https:\/\/blog.gocept.com\/2009\/11\/24\/adding-round-corners-to-boxes-using-css-and-javascript\/","url_meta":{"origin":162,"position":4},"title":"Adding round corners to boxes using CSS and JavaScript","author":"","date":"November 24, 2009","format":false,"excerpt":"Curvycorners has a way to make gorgeous\u00a0roundings to your boxes without having to split each box into pieces of background images. You simply need to include one JavaScript file and add two lines of CSS code to your box (or to the box's class definition). First, include the curvycorners javascript\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3312,"url":"https:\/\/blog.gocept.com\/2019\/05\/10\/celebration-zope-4-final-release\/","url_meta":{"origin":162,"position":5},"title":"Celebration: Zope 4 final release","author":"Michael Howitz","date":"May 10, 2019","format":false,"excerpt":"TL;DR: Zope 4 beta phase ended, final version released! After hard, long years of preparation Earl Zope now finally made it to get a permanent license for the Python 3 wonderland: In September 2016 almost 20 people started with the reanimation of Zope at the Zope Resurrection sprint. This marked\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2019\/05\/fireworks-945386_1920.jpg?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2019\/05\/fireworks-945386_1920.jpg?fit=1200%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2019\/05\/fireworks-945386_1920.jpg?fit=1200%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2019\/05\/fireworks-945386_1920.jpg?fit=1200%2C800&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2019\/05\/fireworks-945386_1920.jpg?fit=1200%2C800&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/162"}],"collection":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/users\/15344399"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/comments?post=162"}],"version-history":[{"count":12,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/162\/revisions"}],"predecessor-version":[{"id":1310,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/162\/revisions\/1310"}],"wp:attachment":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/media?parent=162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/categories?post=162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/tags?post=162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}