Quantcast
Channel: MarsHut
Viewing all articles
Browse latest Browse all 6551

Ajax dropdown population from domain

$
0
0
I am having an issue populating a dropdown from another dropdown with ajax, searched through a lot of examples but the ones i saw are in grails 1.something and gives me a lot more issues when trying to run them. The closest i saw in version 2.something does not make use of a domain class and i find it difficult to relate to my app as well.
Below is my view:

    <g:select name="warehouse.id" from="${Warehouse.list()}" optionKey="id" optionValue="name"

                      noSelection="['':'Choose Table']"

                      onchange="${remoteFunction (

                                      controller: 'warehouse',
                                                action: 'findFieldsForWarehouse',
                                       params:  "'warehouse.id=' + this.value",

                             // update: [success: 'great', failure: 'ohno']
                                 update: 'fieldselection'
                         )}" />

             <g:select name="field.id" from="${[]}" optionValue="name"
                 noSelection="['':'Choose Field']"
           />

And below is my controller:

  def dynamicDropdown = {
    }
    def findFieldsForWarehouse = {

        def warehouse = Warehouse.get(params.warehouse.id)
        println(warehouse.id + 'is warehouse id')
      //  render "done"
     // render(template: "fieldSelection", model: [field: warehouse.fields])

        def telephones = warehouse.collect {[id: it.id, field: it.name]
        }
        println(warehouse.fields)
        render telephones as JSON
      //  render(view: "fieldSelection", model: [warehouseInstance: warehouse])
       // render g.select(optionKey: 'id', from: warehouse.name, id: 'name', name: "name")
        withFormat {
            html {
                render template: 'fieldSelection', model: [cities: warehouse.name]
                println('update successful')
            }}

        println('update successful')

  }

//It is printing update successful on the command line but the second dropdown is not being updated.

Any help appreciated, thanks.
 
 
Adetunji ADEGBITE
IM Address: twonjee2002 [ at ] gmail.com
Skype: teejay.yp
URL: www.simpleefied.com 

Viewing all articles
Browse latest Browse all 6551

Trending Articles