4

A RelationChoice widget in my custom type works fine until collective.js.jqueryui autocomplete is enabled and then it stops working ie stops doing relation lookups; nothing happens when you type in the field.

(In another part of the site I use collective.js.jqueryui autocomplete with Google Maps API to return address suggestions as the user completes an address field.)

The current workaround is to disable collective.js.jqueryui autocomplete when i want to use the RelationChoice widget (and re-enable afterwards). Not a good solution.

  • Plone 4.2.1.1
  • collective.js.jqueryui 1.8.16.9 (also tried 1.10.0.1 - same clash)
  • plone.app.dexterity 1.2.1

Independantly:

  • If i only enable plone.formwidget.autocomplete/jquery.autocomplete.min.js my Google maps lookup doesnt fire (see code below) but the RelationChoice widget works
  • If i only enable collective.js.jqueryui autocomplete my Google maps lookup works but the RelationChoice widget doesnt fire

Code sample:


    $(document).ready(function() {
        initialize();

        $(function() { // Google maps lookup
            $("#address").autocomplete({
                //This bit uses the geocoder to fetch address values
                source: function(request, response) {
                geocoder.geocode( {'address': request.term}, function(results, status) { ...

    ... <input type="text" name="address" id="address" autocomplete="off" class="ac_input">

Is it possible I could re-use plone.formwidget.autocomplete/jquery.autocomplete.min.js in the above code instead? I don't know how to get it to fire my Google maps lookup...? (collective.js.jqueryui autocomplete successfully activates the above function when enabled.)

Aaron Williams
  • 655
  • 4
  • 11
  • Please include some exerpts of relevant code. – Ida Mar 27 '13 at 10:43
  • Could toutpt's answer solve your conflict? – Ida Mar 28 '13 at 06:55
  • Too bad toutp's and my answers couldn't help futher, seems you need to make a closer js-debug-session. Could you proceed any further? And could you paste the js-lines concerning the google-widget? – Ida Apr 19 '13 at 08:10
  • 1
    I have a workaround. I looked at changing out jqueryui library for "select2" library, but didnt want to rewrite my google maps address lokup function, so instead I have added a conditional to the jsregistry.xml so that collective.js.jqueryui.custom.min.js is not called if expression="python:'my-page-with-relationChoice-widget' not in context.portal_url.getRelativeContentPath(context)" So there is no clash on the autocomplete function in the relationChoice form widget Hope the extra overhead per page is ok, i know this is not great but it's a workaround for now. – Aaron Williams May 07 '13 at 06:38

3 Answers3

2

Contenttree widget is based on autocomplete widget.

Autocomplete widget conflict with jqueryui autocomplete plugin.

Using collective.js.jqueryui you can unactivate the autocomplete plugin using the portal_registry.

It makes years that ploneformwidget.autocomplete is broken with jqueryui. There is a branch of plone.formwidget.autocomplete which is based on jqueryui (the branch 2.0) but I don't have already test it with contenttree widget.

So to fix your issue: go to jqueryui controlpanel and uncheck autocomplete plugin.

toutpt
  • 5,145
  • 5
  • 38
  • 45
  • This is the same answer that I gave before, just that you advice to put off the Plone-core-jQuery-option instead of the js of p.f.autocomplete. I think, the latter should remove the contained js'ses and also use the given jQuery-packages instead -> avoid redundancy and skript-conflicts. – Ida Mar 28 '13 at 06:47
  • Conflict reported: https://github.com/plone/plone.formwidget.autocomplete/issues/5 – Ida Mar 28 '13 at 06:54
2

OK, I have done It. At least on Plone 4.3

The first part was, to fully enable the jQuery ui effects in the package. There is a namespace problem and a missing file, that results in .effects() is not a function.

First, download the correct jQueryUI version cd into it and

jquery=/buildout_dir/parts/omelette/collective/js/jqueryui

cp jquery.ui.effect.min.js $jquery/js/jquery.ui.effect.core.min.js

then cd into the $jquery directory and convert all effect packages to correct namespace. Eg:

mv js/jquery.ui.effect-highlight.min.js js/jquery.ui.effect.highlight.min.js

Then replace all occurrences of effects with effect $jquery/config.py. In vim use

:1,$s/effects/effect/g

Secondly, to enable the jQuery based autocomplete widget, cd into the src directory of your buildout and

 git clone https://github.com/plone/plone.formwidget.autocomplete.git plone.formwidget.autocomplete
 git checkout jqueryui-autocomplete

then edit your versions.cfg. For me

plone.formwidget.autocomplete >= 2.0

works. Then edit your buildout.cfg and add the package under zcml and develop. I did a buildout, but it may be enough to restart Zope. The last step is obviously, to visit the portal installer and reinstall the product.

Update

As described in the comments, it was not fully functional. I further had to modify one .js file, namely autocomplete.js from the plone.formwidget.autocomplete package. Here is the result

http://pastebin.com/RPaLk80H

This all together makes the RelationChoiceWidget and the AutocompleteWidget work together in one form. I like it.

I also filed a bug report on github for the jQueryUI package.

moestly
  • 1,681
  • 15
  • 19
  • Thanks ansi_lumen. So that's a monkey patch on collective.js.jqueryui? Thanks for tracking that down. I think I'll leave my conditional for now and when (if) the namespace clash is fixed then i'll remove it... – Aaron Williams May 14 '13 at 01:02
  • I must admit that I posted this after throwing my night at it. Now the widget gets displayed as expected, but it does not really work. I did a `console.log(d)` on the included `autocomplete.js`, which seems to get a wrong data format from the popup and throws an error. I think I need to solve it "finally" in the next days and will update my report in case... – moestly May 14 '13 at 03:08
  • @ansi_lumen: Great, muchas gracias! You can help even more people, if you'd report this also on github.com/plone/plone.formwidget.autocomplete/issues/5, would that be possible for you? – Ida May 14 '13 at 09:42
  • Pull request issued, jQueryui package got fixed after bug report. What would be the single reason to vote me down here?? – moestly May 16 '13 at 00:01
  • @ansi_lumen: No idea who voted you down (maybe the person can leave a note here why?), +1 from me anyway, I haven't reviewed but the package-owners hopefully will soon and merge your contribution. Very much appreciated you took the effort to share, thanks a lot! – Ida May 16 '13 at 10:36
1

Update (according to the question's update):

Referring to Martin's tutorial and the section about relations, Dexterity pulls plone.formwidget.contenttree, which pulls plone.formwidget.contenttree, which pulls plone.formwidget.autocomplete.

The latter includes jQuery's autocomplete-sources, so does collective.js.jqueryui, pulled by your map-product. A conflict is very likely.

Try this:

Ida
  • 3,994
  • 21
  • 40
  • OK i disabled autocomplete in zmi, but then the widget doesnt work. – Aaron Williams Apr 04 '13 at 02:45
  • I re-enabled the autocomplete js in zmi and switched off the jquery-ui autocomplete but then my google map breaks. – Aaron Williams Apr 04 '13 at 02:46
  • I notice there is a 'restrict to authenticated users' flag for the js autocomplete in zmi js_registry. In theory if i turn this off, then i can activate this autocomplete for my google app as well, trouble is i dont know what activation the widget uses... jquery-ui uses `.autocomplete` but i cant figure out how to activate the relationWidget autocomplete... i tried making the class of the input `autocompleteInputWidget` but it doesnt fire the autocomplete event on input... – Aaron Williams Apr 04 '13 at 03:13