Why doesn't 'set selected' work when using apiSettings to populate Semantic UI Dropdown values?

26 views Asked by At

I'm using the Semantic UI Dropdown.

The below works perfectly and selects the values specified:

const users = [
    {value: 1, name: "Atomic Petrie"},
    {value: 2, name: "Jay Hammo"},
    {value: 3, name: "Weaz Whites"},
    {value: 4, name: "Lobo Bongus"},
    {value: 5, name: "Tree Bone"},
]

$('.ui.dropdown').dropdown({
    values: users
});

$('.ui.dropdown').dropdown('refresh');
$('.ui.dropdown').dropdown('set selected', ['1', '3', '2']);

But if I populate the dropdown values with the following:

$('.ui.dropdown').dropdown({
    apiSettings: {url: `${server}/get-people`}
});

The specified values are no longer selected.

The drop down is populated with the retrieved data and the data definitely contains values '1', '3' and '2'.

Interestingly on my backend although the GET request returns the data, none of my console log/dir actually output anything...

// get people for use with Semantic Dropdown
app.get('/get-people', (req, res) => {
    console.log("test")
    sql.connect(db, e => {
        if (e) {
            console.log(e)
            res.status(500).send(e.message)
        } else {
            new sql.Request().query(`
            SELECT
            (
                SELECT 'true' AS 'success', 
                (
                    SELECT id AS 'value', full_name AS [name] 
                    FROM [User] 
                    ORDER BY full_name 
                    FOR JSON PATH
                ) AS 'results'
                FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
            ) AS 'result'
            `, (e, result) => {
                if (e) {
                    console.log(e)
                    return res.status(500).send(e.message)
                } else {
                    console.dir(JSON.parse(result.recordset[0].result), { depth: null });
                    return res.status(200).json(JSON.parse(result.recordset[0].result))
                }
            })
        }
    })
})

This is the Semantic UI page I was using for configuration https://semantic-ui.com/modules/dropdown.html#/examples

Any help would be greatly appreciated.

Thank you.

0

There are 0 answers