retrieve values for select field from ajax?

retrieve values for select field from ajax?

loukinglouking Posts: 259Questions: 52Answers: 0
edited March 2016 in Editor

For one feature on my site I want to use Editor in standalone mode to get from the user arguments for a subsequent URL page access.

My problem is my field select values are dependent on earlier selects. By this I mean after the user selects the first field in the Editor form, the values appropriate for the second field need to be retrieved from the database.

I see the field option has a data suboption where I can specify a function, but it looks like that has to be a synchronous function call. I think it is better for the select be filled in asynchronously, as sync ajax is frowned upon these days. I would retrieve the values outside of Editor, but I don't see an api for field that I can call to set the select options.

Am I missing something?

Note: I also don't quite get http://editor.datatables.net/examples/standalone/simple.html because there is an ajax option -- is that used or necessary for the edit form? Looking at the Ajax data tab, it doesn't look like it is used, but I want to verify what happens when this.submit() is called.

This question has an accepted answers - jump to answer

Answers

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

    First point - I would seriously recommend against using field.data as a function. You need to consider both the setter and getter cases if you do and that complicates matters. Also as you say, it is synchronous only.

    the values appropriate for the second field need to be retrieved from the database.

    dependent() can be used for that. Or you can just attach your own change event listener to the input element and then use field().update() to update the list of options from whatever data source you want.

    there is an ajax option -- is that used or necessary for the edit form?

    It needs to submit the edited data somewhere so it can be recorded (although actually that example doesn't store it in a database). Typically I would expect there to be an Ajax URL, or there would need to be an ajax option as a function with an override.

    Allan

  • loukinglouking Posts: 259Questions: 52Answers: 0

    I'll check into the dependent() api. Since I wrote this I had also started thinking that I don't really have that much data so I can probably pass the whole dependency tree when the page is painted rather than retrieving the next options -- seems attaching my own change event might be the right answer.

    My example doesn't use ajax to process the form because this is just being used as a popup to get arguments for the next page retrieval. I've made this work in a simple case but not yet with the dependencies.

    As always, thanks for your advice.

This discussion has been closed.