cascading select using dependent()

cascading select using dependent()

defdogdefdog Posts: 8Questions: 3Answers: 0

can you help with an example to use the datatables editor php code and dependent() when one select field provides the values to create/limit the values in another select.

Answers

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    I don't have a complete working example yet (good idea for a blog post thought - thanks), but basically what you would do on the client-side is:

    editor.dependent( 'parentField', '/api/options' );
    

    Then on the server-side have /api/options (or whatever your end point is) accept data in the format shown in the dependent() documentation - specifically of interest will be the values['parentField'] parameter.

    Do whatever processing / SQL query is needed to get the options that should be available and then have it reply with JSON in the structure:

    {
      "options": {
        "childField": [
          { "label": ..., "value": ... },
          ...
        ]
      }
    }
    

    Regards,
    Allan

  • defdogdefdog Posts: 8Questions: 3Answers: 0

    thanks i got it working.

This discussion has been closed.