Get label of the plugin select2

Get label of the plugin select2

klermannklermann Posts: 277Questions: 67Answers: 1

Hello Allan, how do I get the text of the plugin select2, because the plugin is sending only the value in order and need to capture the value of the label. How should I do? I tried to do this: "conf._input.text(val)" only it returns the entire list.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    I don't know Select2 inside out I'm afraid - you might need to direct this question at their support channels, but try: conf._input.find('option:selected').text().

    Allan

  • klermannklermann Posts: 277Questions: 67Answers: 1

    Perfect, Thanks very much!!!!!

  • loukinglouking Posts: 259Questions: 52Answers: 0
    edited July 2019

    Just came across this, looking for my use case. If you don't have direct access to conf, also try

    this.field(fieldname).inst().find(":selected").text()
    

    where this is the editor instance

    inst() gets you access to the select2 component, then see https://select2.org/programmatic-control/retrieving-selections and note the cavaet.

This discussion has been closed.