Issues with dynamic select dropdown not populating

Issues with dynamic select dropdown not populating

randy.johnsonrandy.johnson Posts: 18Questions: 8Answers: 0

Url: http://propane.randy1.com/randy

I setup an editor datable with inline editing.

I am trying to get the select dropdown to populate from the local database.

I have tried passing a function to the options:

options: getWarehouseCategories()

as well as via the update statement.

editor.field('intWarehouseCategoryId').update(getWarehouseCategories());

neither of these options are working.

Thank You for your help.

Randy

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Hi,

    Thanks for the link. When I load it it makes a request to get data for the table from "/warehousetypes/ajax_warehouse_subcategories" - however, that is note returning JSON - it looks like it is in fact returning an HTML document. Do I need a log in or something for it to work?

    Allan

  • randy.johnsonrandy.johnson Posts: 18Questions: 8Answers: 0

    oops, that was me not updating the link for the tester page.

    http://propane.randy1.com/randy

    Updated now to point to the right spot.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    editor.field('intWarehouseCategoryId').update(getWarehouseCategories());

    That won't work because getWarehouseCategories returns undefined. The closure function being used in the done callback returns the JSON, but that isn't going anywhere. You would need the Ajax call to be synchronous if you wanted that to work (and even then the return would need to be in the host function), but that's really bad for usability as it locks up the browser.

    Instead, what you could do is:

    function getWarehouseCategories( field ) {
      $.ajax( { ... } )
        .done( function ( json ) {
          field.update( json );
        } );
    }
    

    and in the in main function:

    getWarehouseCategories( editor.field('intWarehouseCategoryId') );
    

    Another option is you have /randy/ajax_warehouse_subcategories return the options information in its data structure and Editor will automatically detect that. This is detailed in this section of the documentation and there is an example here.

    Nice background on the page btw!

    Allan

  • randy.johnsonrandy.johnson Posts: 18Questions: 8Answers: 0

    Worked like a charm. Thank You Allan

This discussion has been closed.