Need help with "type":"select", options:[ using ajax and database

Need help with "type":"select", options:[ using ajax and database

lightfootlightfoot Posts: 9Questions: 5Answers: 0

I have successfully generated select drop-downs that are static (option/value code is fixed). I need to build the "options and "values" dynamically from a database table using ajax. This is associated to Editor generated CRUD screens. The user will select from a database driven drop-down list for a given Editor screens.

I could see using jquery to append "options" and "values" to the HTML generated select elements. If so, where is the best place to incorporate this code. It needs to happen at a place after screens are built and displayd and before the user inputs his/her data.

Is there an existing method (better way) for accomplishing this? I have attempted searching on things like "select" and "select ajax" with little luck.

Thank You,

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin
    Answer ✓

    Yes - use the update() method for the select field type. You basically call that on your field with the options (which will presumably be in the JSON response) - e.g.:

    editor.field('mySelect').update( json.mySelectOptions );
    

    Regards,
    Allan

  • lightfootlightfoot Posts: 9Questions: 5Answers: 0

    Allen,
    Got it working fine!

    It may be work noting for others:
    1) 'mySelect' above is associated with the 'name' of the interested field.
    2) an example of 'json.mySelectOptions' above is like:
    var test={"Text":"MyText","Value":"MyValue"};
    editor.field('Category_1').update(test);
    3) I put this "editor" statement after the establishment of the fields and columns.

    Thank You,

  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin

    Minor update to point 2 - the value (test in this case) should typically be an array.

    Good to hear you got it working.

    Allan

This discussion has been closed.