User field with select_advanced renders selection as [object Object]

Support › General › User field with select_advanced renders selection as [object Object]

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #50256
    ChicharitoChicharito
    Participant

    The user field of type select_advanced displays user names correctly in the dropdown menu. However, once a name is selected, the closed control shows “[object Object]”. The stored value is correctly, and the front end renders properly; the issue is display-only.

    In the file inc/fields/user.php (around line 104), the code forces show_thumbnail to be true for every select_advanced user field. This enables the setObjectThumbnailTemplate() function in js/select-advanced.js, which assigns options.templateSelection to options.templateResult. The templateResult function returns a jQuery object. Although the bundled select2 handles a jQuery return from templateResult correctly, it displays “[object Object]” when using templateSelection.

    This was confirmed in the browser console on the edit screen:

    $sel.select2({ templateSelection: d => $('<span>').text(d.text) }); // shows [object Object]
    $sel.select2({ templateSelection: d => d.text });                   // renders correctly
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.