In a Standalone Editor is it possible to use the options (for a select control) from the data source

In a Standalone Editor is it possible to use the options (for a select control) from the data source

brendonsbrendons Posts: 39Questions: 14Answers: 1

I am populating a standalone editor from ajax which returns the data for advisorId:

editor.edit(ID, false).set('est.AdvisorID', advisorId).buttons({label: "Save", ...}).open();

This field is a select input and the keys:values come from options in the datasource.

Field::inst('est.AdvisorID')
                    ->options( Options::inst()
                        ->table('(SELECT ID, AdvisorFirstName, AdvisorLastName
                                FROM enrollment_advisors 
                                WHERE AdvisorArchived = 0) as T1')
                        ->value('T1.ID')
                        ->label(array('T1.AdvisorFirstName', 'T1.AdvisorLastName'))
                    )
                    ->setFormatter( 'Format::nullEmpty' )
                    ->getFormatter( 'Format::nullEmpty' ),

In a normal editor (that is attached to a table) this works fine, but for this standalone editor, is it possible to pass the key:value pairs from the options to the standalone editor field? If not, is there another way?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin
    Answer ✓

    The way it works in a DataTables connected Editor is that Editor listens for the xhr event when DataTables loads data. Editor will then search for the options and populate the list if found.

    Since there is no Ajax event to listen for in a standalone Editor, what you need to do is make the Ajax call to get the options yourself and then use the update method of the select field type to populate the options.

    Allan

  • brendonsbrendons Posts: 39Questions: 14Answers: 1

    set the options for a standalone editor select field:

    var optionsA = [];
                    $.getJSON("php/lookupAdvisorsById.php",
                        {
                            term: "-1"
                        },
                        function (data) {
                            var option = {};
                            $.each(data, function (i, e) {
                                option.label = e.text;
                                option.value = e.id;
                                optionsA.push(option);
                                option = {};
                            });
                        }
                    ).done(function () {
                        enrEditor.field('est.HomeroomAdvisor').update(optionsA);
                    });
    

    Thanks to Allan for showing me how to do this.

This discussion has been closed.