User field with select_advanced renders selection as [object Object]

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

Viewing 3 posts - 1 through 3 (of 3 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
    #50257
    PeterPeter
    Moderator

    Hello Chicharito,

    Thanks for reaching out.

    This issue has been fixed in this PR https://github.com/wpmetabox/meta-box/pull/1716
    it will be included in the next update of Meta Box plugin.

    Let me know if you have any questions.

    #50258
    ChicharitoChicharito
    Participant

    Perfect!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.