retrieve select field label

retrieve select field label

jfrjfr Posts: 71Questions: 24Answers: 0
edited September 2015 in Editor

Hi

I am trying to retrieve the label of a select field initialize like

editor.add( {
    type:     'select',
    label:    'Locations:',
    name:     'locations',
    multiple: false,
    separator: ',',
    options: [
        { label: 'Edinburgh', value: 51 },
        { label: 'London',    value: 76 }
        // etc
    ]
} );

There is no problem with the

editor.field("locations").val();

witch return the value selected for the field name locations
I would like to retrieve the label of that selected field but

editor.field("locations").label();

return

"locations:<div data-dte-e="msg-label" class="DTE_Label_Info"></div>"

thanks in advance

This question has an accepted answers - jump to answer

Answers

  • RagnarGrootKoerkampRagnarGrootKoerkamp Posts: 48Questions: 14Answers: 1

    Did you manage to solve this issue in a nice way? Currently, I am having the same problem and I can't see a nice way around it, except stripping everything after the first '<' from the string.

  • RagnarGrootKoerkampRagnarGrootKoerkamp Posts: 48Questions: 14Answers: 1

    I found a better way: use editor.field(...).s.opts.label. It would be nice if the input options were accessible via a field(...).options() function.

  • allanallan Posts: 63,520Questions: 1Answers: 10,473 Site admin
    Answer ✓

    You would use editor.field( 'myField' ).input().find( 'option:selected' ).text(). This is based on the field().input() field returning the select element and then just use a little jQuery to get it.

    You should never use the s property - it is not documented and is considered private. It's internal parameter, can, will and do change between versions.

    Allan

This discussion has been closed.