Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9076887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:12:27+00:00 2026-06-16T19:12:27+00:00

I have been following the guide from Alidad’s blog to enable jquery auto completion

  • 0

I have been following the guide from Alidad’s blog to enable jquery auto completion within grails:

http://alidadasb.blogspot.co.uk/2011/12/enabling-jquery-autocomplete-with.html

Country.groovy

package rentspace
    class Country {
         String name
         static hasMany = [cities:City] 
    }

City.groovy

package rentspace

class City {
    //static belongsTo = [country:Country]
    static belogsTo = Country
    Country  country
    String name
    static constraints = {}
}

GSP Page:

<g:autoComplete id="countrySearch"
                action='autocompleteCountry'
                controller='any'
                domain='rentspace.Country'
                searchField='name'
                collectField='id'
                value=''
/>

<g:textField id="hiddenState"  name="hiddenState" value=""/>

<label>City:</label>
<g:autoComplete name="citySearch" id="citySearch"
                cid=""
                action='autocompleteCityAction'
                controller='any'
                domain='rentspace.City'
                searchField='name'
                value=''
/>

AutoCompleteTagLib.groovy

package rentspace

class AutoCompleteTagLib {
 ..
                if (attrs.style) styles = " styles='${attrs.style}'"

        if (attrs.cid) 
           cid="&cid="+attrs.cid
        else
          cid=""

             .......

                out << "&order="+attrs.order
        out << ""+cid



                out << "&collectField="+attrs.collectField

        out << "',select: function(event, ui) {"
        out << "    \$('#hiddenState').val(ui.item.id);},"
        //out << "  \$('#citySearch').attr('cid',ui.item.id);},"
        out <<" search: function() {"
        out << "\$('#hiddenState').val('');"
        //out << "\$('#citySearch').attr('cid','');"
        out <<"}"   

                out << ", dataType: 'json'"
                out << "});"
        out << "    });"
        out << "</script>"

        }

        def autoCompleteHeader = {
                out << "<style>"
                out <<  ".ui-autocomplete-loading"
                out << "        { background: white url(${resource(dir:'images',file:'ajax-loader.gif')}) right center no-repeat   }"
                out << " </style>"
        }
}

My question is related to dual values returned by jquery, it does appear to be working if I return the value to a hidden or text field box. What I am trying to do is return the country id to the second auto complete box being citySearch.
So once the user auto completes the country the country id is returned as cid=’1′ or whatever the id is to the cid attribute of citySearch auto complete box.

in the tag lib there is a segment commented out which is where it succeeds in returning or updating the value of hiddenState field but no matter what attempt made to update the cid value I keep on failing ?

        //out << "  \$('#citySearch').attr('cid',ui.item.id);},"

Has anyone succeeded in doing anything like this ?

E2A:

https://github.com/vahidhedayati/grailscountrycity

Project can be downloaded from above link, there is some more information regarding the issue within the readme

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:12:29+00:00Added an answer on June 16, 2026 at 7:12 pm

    Issue has been solved here by Alidad: { countryid: \$(‘#hiddenField’).val() }

    https://github.com/alidadasb/CountryCityAutoComplete

    out << "\$('#" + attrs.id+"').autocomplete({ "
                        out << " source: "
                        out << " function(request, response) { "
                        out << " \$.getJSON(' "
                        out << createLink(link)
                        out << "?"
                        out << "term=' + request.term + '"
    out << "&domain="+ attrs.domain
                        out << "&searchField="+attrs.searchField
                        out << "&max="+attrs.max
                        out << "&order="+attrs.order
                        out << "&collectField="+attrs.collectField
                        out << "', { countryid: \$('#hiddenField').val() }, "
                        out << " response); } "
                        out << ", dataType: 'json'"
                        out << "});});"
                        out << "</script>"
    

    Working version can be seen here:
    http://countrycity.cloudfoundry.com

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been following Railscasts guide for converting my db from sqlite to postgreSQl.
I have been trying to get a basic reorderlist working following this guide ->
I've been following through the tutorial / guide published here: http://www.adobe.com/devnet/html5/articles/flame-on-a-beginners-guide-to-emberjs.html Which has been
I have been following this guide on how to call a member function of
After following instructions from orbeons wiki From: http://wiki.orbeon.com/forms/doc/user-guide/form-builder-user-guide#TOC-Creating-a-PDF-template-for-use-wit Non-exclusive checkboxes Use PDF checkboxes Use
I've been following the guide microsoft have made for setting up the Kinect SDK
I have been following this guide , which goes over adding a file to
I've been following this guide for displaying a Bitmap in OpenGL http://obviam.net/index.php/texture-mapping-opengl-android-displaying-images-using-opengl-and-squares/ I have,
I've been following this guide about multiple jquery time span sliders. Am trying to
I've been following the Subversion -> Git migration guide here: https://stackoverflow.com/a/3972103/1107232 I'm migrating from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.