[Cubicweb] On-the-fly modification of forms

Sylvain Thénault sylvain.thenault at logilab.fr
Mon Aug 20 12:40:39 CEST 2012

On 17 août 09:55, Stéphane Bugat wrote:
> Dear all,

Hi Stéphane,
> I'd like to have a formview that changes according to one of it formfields.
> To be more specific, something like the "one-way" or "two-way" boolean field for trip forms, where for instance one or two date widgets would appear for selection to the user.
> How can I customize a FormView instance so that it catches any change to one of its BooleanField for instance? Since Controllers are called only when the form is submitted, I guess there should be another solution...

You usually don't want client/server exchange for such things. You should
rather use javascript and 'onchange' attribute on the widget used for your
boolean field. To do so, you've to explicitly instantiate the widget for
your field: 

  myfield = BooleanField(attrs={'onchange': 'jsFunction()'})

or using uicfg:

  uicfg.autoform_field_kwargs.tag_attribute(('Type', 'attribute'), {'widget': BooleanField(...)})

Then, welcome to the javascript land ;)

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