[Cubicweb] On-the-fly modification of forms

Sylvain Thénault sylvain.thenault at logilab.fr
Wed Aug 22 10:56:34 CEST 2012

On 22 août 09:57, Stéphane Bugat wrote:
> For my personal project, I've chosen finally to create a kind of "AirportSearch" entity, and gave up the ad hoc field form method... This is more convenient as a user can therefore have a favourite search, can access its last 10 searches, and so on. 
> Following the example given in http://docs.cubicweb.org/devweb/edition/examples.html, I'd like to modify the default FormView for the AirportSearch entity. First, there is some slight differences with the given example derived from ChangeStateFormView: for entity edition it seems that I have to overwrite the EditionFormView class of cubicweb.web.views.editforms, is that correct?

> After, it seems that EditionFormView does not have this convenient method, get_form(), that returns the current entity form. In place of I found a render_form() method, which controls the rendering of the form. My problem is that I just want to add some formfields and not rewrite the whole thing... How do I proceed?

The EditionFormView class provides the init_form method for this purpose (given 
the selected form as argument, does nothing by default). So you can override
it and add desired fields there, that should do the trick. At some point, we
shall probably unify those get_form / init_form mecanism (my preference going
to get_form which is the most flexible).

Sylvain Thénault, LOGILAB, Paris ( - Toulouse (
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org

More information about the Cubicweb mailing list