Extract the value from type field autocomplete

Extract the value from type field autocomplete

EtoffeEtoffe Posts: 4Questions: 1Answers: 0

i have field type autocomplete and another field type select

When i select one option from field type select i can extract the value selected with the code :

            var colonneoption = $('select option:selected', editorModifyAttribut.node('colonne')).text();

but if i try the same code with the field type autocomplete it doesn't work the variable is empty

            var colonneautocomplte = $('select option:selected', editorModifyAttribut.node('colonneautocomplete')).text();

i know the logic off the form is good because when i check all the values sended to the sever by the form i see the good value for this field but i need to check something before to send to the server.

Could tell me which syntaxe i can use to extact the good value ?

Thank you for your help

Michel

Answers

  • allanallan Posts: 61,453Questions: 1Answers: 10,055 Site admin

    I find jQuery UI AutoComplete really difficult to work with for labels and values!

    This SO thread shows how you can listen for the autocompleteselect event to get both the label and value.

    Allan

  • EtoffeEtoffe Posts: 4Questions: 1Answers: 0
    edited June 2021

    hi allan,

    sorry but it doesn't work.
    I think i dont use the right event or syntaxe.

    Below the description of the field colonneauto:

                editorModifyAttribut.add(
                    {
                        label: "Colonne auto",
                        name: "colonneauto",
                        placeholder: "Taper le nom",
                        type: "autoComplete",
                        "opts": {
                            "source":
                                function (request, response)
                                {
                                    //console.log("request");
                                    //console.log(request);
                                    var colonneArray= new Array();
                                    $.ajax({
                                        'url' : '/etoffe/product/autocomplete/colonne',
                                        async: false,
                                        dataType: 'json',
                                        data: {
                                            term: request.term,
                                            class: "Produit"
                                        },
                                        success: function (json) {
    //                                    console.log(json);
                                            var listeColonne = {};
                                            for(var i=0;i<json.length;i++){
    
                                                var label    =  json[i].label + " ("+json[i].type+")"+ " ("+json[i].locale+")";
                                                var value    = json[i].value;
                                                //obj= { "label" : json[i].label, "value" : json[i].value };
                                                obj= { "label" : label, "value" : label };
                                                colonneArray.push(obj);
                                            }
                                            response ( colonneArray )
                                        }
                                    });
                                }
                        }
                    }
                )
    

    what is the good syntaxe to intercept the event when something change on the field and when is selected

    when the field is a type select the syntaxe is :

    $('select option:selected', editorModifyAttribut.node('colonne')).text();

    and it works !!!

    what is the equivalent for the field colonneauto because witw the syntaxe below

    $('select option:selected', editorModifyAttribut.node('colonneauto')).text();

    it doesn't work

    thank you for your help

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

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    Try using val() rather than text(), and see if that does the trick,

    Colin

  • EtoffeEtoffe Posts: 4Questions: 1Answers: 0

    hi colin,

    sorry no change always nothing

    it is the same problem and about this subject the event triggereg for the field select with the syntaxe :

            $('select', editorModifyAttribut.node('colonne')).on('change', function (e) {
    

    works !!

    but the same syntaxe with field autocomplete

            $('select', editorModifyAttribut.node('colonneauto')).on('change', function (e) {
    

    doesn't work too

  • EtoffeEtoffe Posts: 4Questions: 1Answers: 0

    hi allan and colin,

    i found the solution .
    Thank you for your help.

    Michel

  • allanallan Posts: 61,453Questions: 1Answers: 10,055 Site admin

    Hi Michel,

    Great to hear you got it working. Could you let us know the answer in case anyone else finds this thread and is wondering the same thing?

    Thanks,
    Allan

Sign In or Register to comment.