Re: [Zope3-Users] Arranging widgets in a form / Limit size of input fields
Hi, On Wed, 2007-05-02 at 15:07 +0200, Hermann Himmelbauer wrote: Hi, I'd like to know how to arrange (e.g. group) widgets in a form with formlib. One way would be to create a custom template file, where each widget is placed via HTML. However, this is quite some work. I've often done this and it doesn't seem like too much work. But I don't dispute your evaluation. Another way would be to place the fields via CSS. How do you deal with form layout? Moreover I wonder if it's possible to customize the attributes size and maxlength of HTML input fields via the zope schema. Schemas offer the attribute max_length, however this does not affect the rendered HTML - size seems to be always set to 20, maxlength is never set. My approach is different to Fred's because I rarely call setUpWidgets in my form code. I have a bunch of custom widgets in a known place and use custom_widget. Some widgets are for special fields or needs and some are as simple as this one. I reuse it very often.: class DescriptionWidget(TextAreaWidget): def __init__(self, context, request): super(TextAreaWidget, self).__init__(context, request) self.height = 3 self.width = 85 Best regards, Darryl Cousins Is there any solution to this? Best Regards, Hermann ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Arranging widgets in a form / Limit size of input fields
One way would be to create a custom template file, where each widget is placed via HTML. However, this is quite some work. I've often done this and it doesn't seem like too much work. But I don't dispute your evaluation. I've used my own templates as well. It is more work than having autogenerated form but it is not so hard. In fact you may change template to use divs instead of tables and then play with css only to arrange your forms. My approach is different to Fred's because I rarely call setUpWidgets in my form code. I have a bunch of custom widgets in a known place and use custom_widget. Some widgets are for special fields or needs and some are as simple as this one. I reuse it very often.: class DescriptionWidget(TextAreaWidget): def __init__(self, context, request): super(TextAreaWidget, self).__init__(context, request) self.height = 3 self.width = 85 I've used this kind of solution as well. AFAIK for textarea html fields you can't set something like maxlength. You have to use javascript for that. -- Maciej Wisniowski ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Arranging widgets in a form / Limit size of input fields
On 5/3/07, Maciej Wisniowski [EMAIL PROTECTED] wrote: AFAIK for textarea html fields you can't set something like maxlength. You have to use javascript for that. That's correct; maxlength is for input with type=text or type=password. -Fred -- Fred L. Drake, Jr.fdrake at gmail.com Chaos is the score upon which reality is written. --Henry Miller ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Arranging widgets in a form / Limit size of input fields
On 5/3/07, Darryl Cousins [EMAIL PROTECTED] wrote: My approach is different to Fred's because I rarely call setUpWidgets in my form code. I have a bunch of custom widgets in a known place and use custom_widget. Some widgets are for special fields or needs and some are as simple as this one. I reuse it very often.: This is probably a better pattern most of the time. I suspect part of my setUpWidgets() addiction comes from the early days of zope.formlib, before custom_widget was added. -Fred -- Fred L. Drake, Jr.fdrake at gmail.com Chaos is the score upon which reality is written. --Henry Miller ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Arranging widgets in a form / Limit size of input fields
Am Donnerstag, 3. Mai 2007 08:57 schrieb Darryl Cousins: Hi, On Wed, 2007-05-02 at 15:07 +0200, Hermann Himmelbauer wrote: Hi, I'd like to know how to arrange (e.g. group) widgets in a form with formlib. One way would be to create a custom template file, where each widget is placed via HTML. However, this is quite some work. I've often done this and it doesn't seem like too much work. But I don't dispute your evaluation. Well, when looking at the template, I roughly have to write this for every widget: div class=label label for=field.name title=The widget's hint tal:attributes=for view/widgets/foo; title view/widgets/foo/hint tal:content=view/widgets/foo/labelLabel/label /div div tal:condition=view/widgets/foo/error tal:content=structure view/widgets/foo/errorError/div div class=field input tal:replace=structure view/widgets/foo / /div In my case, I have several forms with e.g. 10-15 fields, so this adds up and in the end the templates are quite complex. If there were some shortcut or macro which generates the above HTML-code, it would be a lot easier, perhaps there's a decent solution? If it would looke something like this, it would be much easier to manage: span tal:content=view/widgets/foo/gen_html / Best Regards, Hermann -- [EMAIL PROTECTED] GPG key ID: 299893C7 (on keyservers) FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7 ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Arranging widgets in a form / Limit size of input fields
On 5/3/07, Hermann Himmelbauer [EMAIL PROTECTED] wrote: Well, when looking at the template, I roughly have to write this for every widget: Another approach is to use a template that uses a view on each widget; that view can be whatever it needs to be, and let's you have per-field bits completely separate from the form template, and be specialized more readily. -Fred -- Fred L. Drake, Jr.fdrake at gmail.com Chaos is the score upon which reality is written. --Henry Miller ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Arranging widgets in a form / Limit size of input fields
In my case, I have several forms with e.g. 10-15 fields, so this adds up and in the end the templates are quite complex. If there were some shortcut or macro which generates the above HTML-code, it would be a lot easier, perhaps there's a decent solution? If it would looke something like this, it would be much easier to manage: span tal:content=view/widgets/foo/gen_html / Isn't tal:repeat enough?? Something like: tal:block tal:repeat=widget view/widgets div class=label label for=field.name title=The widget's hint tal:attributes=for widget; title widget/hint tal:content=widget/labelLabel/label /div div tal:condition=widget/error tal:content=structure widget/errorError/div div class=field input tal:replace=structure widget / /div /tal:block If you need specific widgets order then you may use: form.FormFields(interfaces.ISomeInterface).select('field1', 'field2',) Another possibility io define function in your view class like: widgetTempl = ViewPageTemplateFile('widgetsection.pt') def genWidgetHtml(self, widget): return self.widgetTempl(widget=widget) and create file widgetsection.pt with content like: tal:block tal:define=widget python: options.get('widget', None) div class=label label for=field.name title=The widget's hint tal:attributes=for widget; title widget/hint tal:content=widget/labelLabel/label /div div tal:condition=widget/error tal:content=structure widget/errorError/div div class=field input tal:replace=structure widget / /div /tal:block Then in your pageform.pt just call for every widget something like: div tal:replace=python: view.getWidgetHtml(view.widgets['foo'] / Above code is from head so may be buggy or incomplete. -- Maciej Wisniowski ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Arranging widgets in a form / Limit size of input fields
Hermann Himmelbauer wrote: I'd like to know how to arrange (e.g. group) widgets in a form with formlib. One way would be to create a custom template file, where each widget is placed via HTML. However, this is quite some work. I've often done this and it doesn't seem like too much work. But I don't dispute your evaluation. Well, when looking at the template, I roughly have to write this for every widget: div class=label label for=field.name title=The widget's hint tal:attributes=for view/widgets/foo; title view/widgets/foo/hint tal:content=view/widgets/foo/labelLabel/label /div div tal:condition=view/widgets/foo/error tal:content=structure view/widgets/foo/errorError/div div class=field input tal:replace=structure view/widgets/foo / /div Hi Hermann, I started a form layout add-on for formlib, see snippet below.. It's a very rudimentary first cut, and only provides a grid (table) layout. I can't see myself getting any time to work on it in the immediate future. If you think it might be useful I can send you the package (which includes doctests). Regards -Tom class SearchForm(LayoutMixin, form.EditForm): interface.implements(ISearch) form_fields=form.Fields(ISearch) form_fields['results'].custom_widget = HTMLDisplayWidget form_method='GET' form_layout=VertLayout( ).addText(uTraining Guide, ).addWidget('search_type', label=uSelect one of the following items, ).addText(uhr / ).add(GridLayout( ).addText(uSearch Criteria, 0, 0, colspan=5, ).addWidget('region', 1, 0, ).addWidget('institution', 1, 2, ).addWidget('skill', 2, 0, ).addWidget('text', 2, 2, ).addAction('search', 2, 4, ).addWidget('results', 3, 0, colspan=5, label=None, ) ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Ch 7, lookup error in getMultiAdapter
Working through Web Component Development with Zope 3 Second Edition, I'm stuck just at the point it gets more interesting. In the interactive debug session looking at a basic view, I get a lookup error at... view = getMultiAdapter((lasagne, request), name=u'index.html') I've confirmed that both lasagne, and request are objects. the error reads in part, line 103 in multiadapter ... zope.component.interfaces.ComponentLookupError... And related to this, when I open the browser to the recipes stored in root http://localhost:8080/minestrone as the example shows, I get The page that your are trying to access is not available, even though ministrone is in the root and shows up in the ZMI I need help getting further in my studies. If there is a FAQ or archive if this list please let me know where it is. (The configuration files and relevant py files are included) Robert configure.zcml Description: Binary data from zope.publisher.browser import BrowserPage class ViewRecipe(BrowserPage): def __call__(self): response = self.request.response response.setHeader('Content-Type', 'text/plain') return self.context.namefrom persistent import Persistent from zope.interface import implements from worldcookery.interfaces import IRecipe class Recipe(Persistent): implements(IRecipe) name = u'' ingredients = [] tools = [] time_to_cook = 0 description = u'' from zope.component.factory import Factory recipeFactory = Factory( Recipe, title=uCreate a new recipe, description = uThis factory instantiates new recipes. ) ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users