Deform forms select2 and ajax

86 views
Skip to first unread message

Jo G

unread,
Sep 11, 2016, 5:30:57 PM9/11/16
to pylons-discuss
Hi, I have a pyramid based application using substanced and deform. I am using a select2 drop down pre-populated with a list of items. The list is very long and takes forever to load. Looking at select2 I should be able to use an Ajax call to a pyramid view to return a subset of the data.
Deform uses an old version of select2 and I'm finding it hard to get it and substanced to play nicely together.
My approach would be:
Define a view that returns a subset of data
Create my own widget based on the select2 widget
Write a new template for the widget
Make the form use Ajax

Anybody done this or can help?

Is there any reason I couldn't use an updated version of select2 jquery?

Is there a better widget I could use? I need to display a text value and return an associated integer ID.

Thanks in advance.

Thierry Florac

unread,
Sep 12, 2016, 2:54:26 AM9/12/16
to pylons-...@googlegroups.com
Hi,

I think "select2" is a perfect candidate for your needs.
I use it in my Pyramid applications but with z3c.form package and it works perfectly with AJAX calls.
The simplest way is probably to create a JSON view which returns a list of objects containing "id" and "text" attributes matching text you started to enter.
I can help you concerning the required HTML, AJAX and Javascript integration, but I don't know "deform" package requirements...

Regards,
Thierry


--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/474fc6cd-87d6-4066-8dab-03d00958f035%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

tonthon

unread,
Sep 12, 2016, 3:45:49 AM9/12/16
to pylons-...@googlegroups.com
Hi,

starting from the original deform widget, you should be able to build a
custom one fitting your needs.

If you're using deform's requirements to generate the script tags in
your pages, you could set custom widget requirements for a more recent
version of select2.

The original widget's code :
https://github.com/Pylons/deform/blob/master/deform/widget.py
https://github.com/Pylons/deform/blob/master/deform/templates/select2.pt

The docs :
http://docs.pylonsproject.org/projects/deform/en/latest/widget.html#writing-your-own-widget
http://docs.pylonsproject.org/projects/deform/en/latest/widget.html#specifying-widget-requirements

Hope this can help
Regards

Gaston Tjebbes
http://majerti.fr

Jo G

unread,
Sep 14, 2016, 10:01:31 AM9/14/16
to pylons-discuss
Many thanks - we had got that far already and with a bit more effort now have a select2 which returns results from a solr search. Just need to be able to select values now!
Reply all
Reply to author
Forward
0 new messages