Problem when using the "beforeRetrieve" function

Roger Padilla's Avatar

Roger Padilla

30 Mar, 2010 03:53 PM

I'm using Drupal so I need to pass the parameters as URL's fragments.

As I need an URL like "http://my-domain/cities-autocomplete/01-miami" (where 01 is the {country_id} and miami the {part_name_city}), then I'm using the 'beforeRetrieve' function to get the value of the field 'select' country and then pass
it through the URL.

The URL is correctly created, and the JSon response is also correctly received in the client.
But for some odd reason the plugin always shows "Not Results" when using the 'beforeRetrieve' function.
To prove it, I've commented out the lines number 236-239 (where 'beforeRetrieve' is called) and then the
plugin works fine. In conclusion, seems there exists a problem with such funtion.

Usage of the library from PHP:

                         $("#edit-field-ciudad-llegada-evento").autoSuggest(
                "/cities-autocomplete",
                {
                    asHtmlID: "ciudad_llegada",
                    startText: "'. t('Ingrese la Ciudad') . '",
                    emptyText: "'. t('No hay resultados') . '",
                    limitText: "'. t('Solo se permite una Ciudad') . '",
                    queryParamsStart: "",
                    queryParamValSign: "",
                    queryParam: "/",
                    selectedValuesProp: "value",
                    selectedItemProp: "name",
                    searchObjProps: "name",
                    neverSubmit: true,
                    selectionLimit: 1,
                    minChars: 3,
                    beforeRetrieve: function(part_city_name){
                        var country_id = $("#edit-field-pais-llegada-evento").val();
                        return country_id + "-" + part_city_name;
                    }
                }
            );';

Received JSon:

[ { "value": "412850", "name": "Batallon Cartagena" }, { "value": "413938", "name": "Cartagena" }, { "value": "413939", "name": "Cartagena del Chaira" }, { "value": "414565", "name": "Caserio Punta de Cartagena" }, { "value": "415981", "name": "Cuarteles del Batallon Cartagena" }, { "value": "425079", "name": "Porton de Cartagena" }, { "value": "425635", "name": "Punta de Cartagena" } ]

  1. 1 Posted by Roger Padilla on 30 Mar, 2010 03:57 PM

    Roger Padilla's Avatar

    As you can see, the JSon response is well formatted, but the autocomplete list does not appears when the function 'beforeRetrieve' is used.

    NOTE: 'queryParamsStart' and 'queryParamValSign' are two new parameters I've added to the library to make optional the "?" and the "=" in the URL.

    Thanks in advance.

  2. 2 Posted by Roger Padilla on 30 Mar, 2010 04:13 PM

    Roger Padilla's Avatar

    The problem seems to appears when is included the char '-'.

    Is there some way to allows the usage of such char as part of my params?

    Thanks again,
    Roger

  3. 3 Posted by Roger Padilla on 30 Mar, 2010 05:23 PM

    Roger Padilla's Avatar

    Hey I've found a solution. I've added a optional parameter named 'subPath', which is used to prepend a frament to the URL before append the query parameter.

    I've attached the patch including the others new 2 parameters I've added.

    There is now possible to call the plugin in the way below and to obtain a URL like this: "http://my-domain.com/cities-autocomplete/57/cartagena".
    Please note that is useful for frameworks like Drupal, CodeIgniter, etc, where friendly URLs are used.

    $("#edit-field-ciudad-evento").autoSuggest(

            "/cities-autocomplete/",
            {
                asHtmlID: "ciudad",
                startText: "Ingrese la Ciudad",
                emptyText: "No hay resultados",
                limitText: "Solo se permite una Ciudad",
                queryParamsStart: "",
                queryParamValSign: "",
                queryParam: "",
                selectedValuesProp: "value",
                selectedItemProp: "name",
                searchObjProps: "name",
                neverSubmit: true,
                selectionLimit: 1,
                minChars: 3,
                subPath: function(){
                    var country_id = $("#edit-field-pais-llegada-evento").val();
                    return country_id + "/";
                }
            }
        );
    

    This plugin is great, thanks a lot!
    Roger

  4. 4 Posted by A Maidheen on 13 Dec, 2012 12:16 PM

    A Maidheen's Avatar

    Hi,
    I am using your plugin. I need to add extra params to the url after the item is selected or removed.
    I dont want to show the already selected items in the search list

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac