[Cubicweb] On-the-fly modification of forms

St├ęphane Bugat stephane.bugat at free.fr
Wed Aug 22 14:03:33 CEST 2012

> Huum, that's because you also have to override
> editforms.CreationFormView.
>   class AirportSearchCreationFormView(AirportSearchEditionFormView):
>     __select__ = CreationFormView.__select__ &
>     specified_etype_implements('AirportSearch')
> should be enough.

Well, unfortunately it is not... Even with this mod I still get a 'normal' creation form view and my boolean field is not added at all.

BTW, the 'form.append' method did not work, but I discovered some better methods like insert_field_before, so I modified my init_form like this:

    def init_form(self, form, entity):
        oneway = ff.BooleanField(
                label=_('Search type: '),
                choices=(u'single airport', u'trip'),)
        form.insert_field_before(oneway, u'airport_a_eid', 'subject')
        airport_a_field = form.field_by_name(u'airport_a_eid', 'subject')
        airport_a_field.widget = fw.LazyRestrictedAutoCompletionWidget(

As mentioned, the boolean field is not shown in the creation form. However, I did create an AirportSearch object and tried to modify it afterwards, but I just got an error: "TypeError: sequence item 1: expected string or Unicode, NoneType found" for "/usr/lib/python2.6/dist-packages/cubicweb/web/views/forms.py, line 244, function build_context".

Any idea about that?

More information about the Cubicweb mailing list