How get the option label from field Editor

How get the option label from field Editor

mromemrome Posts: 8Questions: 3Answers: 0
edited March 2021 in Free community support

Hi all,
I use editor extension and i declared a field type select .

, {
                    label : 'Attribut',
                    name : 'attribut',
                    type : 'select',
                        options: [
                            { label: "Ajouter",    value: "add" },
                            { label: "Enlever",   value: "remove" }
                        ]
                    },
                },

i declared a event with the following code :

            $('select', editorAddAttribut.node('attribut')).on('change', function (e) {
                var attributObj =  editorAddAttribut.get('attribut');
                var input = editorAddAttribut.field('attribut');

                console.log( "attributObj: ");                           
                console.log( attributObj);                           
                console.log( "input.get: ");
                console.log( input.get());

                setOptionList( editorAddAttribut.get('attribut'),'Codeunique','AttributValue' )
            } );

Output :
attributObj:
add

Input.get:
add

I would like display the label instead the value but it doesn't work or i don't know how to do.
In my case i want to have following output "Ajouter" when i selected first option.

i try different syntax but nothing work.

Thank you for your help

Michel

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    I'm not too clear on the problem, but you can use field().label() to get the label for the field. If that doesn't help, could you link to your page please so we can take a look,

    Colin

  • mromemrome Posts: 8Questions: 3Answers: 0

    Hi colin,

    if i use field().label() i display the label of the field in my case "Attribut" but i want the label of the option selected and in my case this is the first in my example
    { label: "Ajouter", value: "add" },
    and it should be "Ajouter"

    and with event declared i use the code :
    var input = editorAddAttribut.field('attribut');
    and input.get() display the value "add' but not the label "Ajouter"

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    Hi again,

    I see, you could try one of these two options here - the second would be best as making proper use of the API:

      console.log('select: ' + $('div.DTE_Field_Name_office select option:selected').text())
      console.log('select: ' + $('select option:selected', editor.node('office')).text())
    

    See example here: http://live.datatables.net/bimakubo/2/edit

    Colin

  • mromemrome Posts: 8Questions: 3Answers: 0

    Hi colin,

    Thank you it is work fine.

    thank you for your help.

    have nice WE.

This discussion has been closed.