[Cubicweb] On-the-fly modification of forms

Stéphane Bugat stephane.bugat at free.fr
Mon Aug 20 13:53:10 CEST 2012


Sylvain,

Yes I thought naively that I could avoid the wonderful world of javascript (which for me is limited right now).
I do understand that in terms of performance it would be a bad idea to have client/server exchange just for that.
Well, I guess I'll have to take two paracetamol pills and get into it, unfortunately.
Thanks for the tip!

Stéphane
----- Mail original -----
> De: "Sylvain Thénault" <sylvain.thenault at logilab.fr>
> À: "Stéphane Bugat" <stephane.bugat at free.fr>
> Cc: cubicweb at lists.cubicweb.org
> Envoyé: Lundi 20 Août 2012 12:40:39
> Objet: Re: [Cubicweb] On-the-fly modification of forms
> 
> 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 (01.45.32.03.12) - Toulouse
> (09.54.03.55.76)
> 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