Autocomplete issue on click showing value instead of mantain label

Autocomplete issue on click showing value instead of mantain label

slaskskslasksk Posts: 3Questions: 1Answers: 0
edited April 2020 in Editor

Hello, im using autocomplete with the editor modal, i get label and value via ajax, when i select an option, instead of mantain the label, it shows the value(in this case its the ID), if i dont select and option, and press Update it send the label to the POST.

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        ajax: "Checklists/edit_checklist_info",
        idSrc:  'list_id',
        table: "#checklist_edit",
        fields: [ {
                label: "Item:",
                name: "name",
                "type": "autoComplete",
                "opts": {
                    "source": 
                       url + "/checklistapp/admin/checklists/amb_items_get_optionsJson/",       
                }
                }, {
                label: "Quantidade",
                name: "quantity",
            }
        ]
    } );

https://prnt.sc/s7h3w2
After i click the option it stays like this : https://prnt.sc/s7h4nu

Json response:

[{"value":"1","label":"Compressa 10x10"},{"value":"2","label":"Compressa 5x5"},{"value":"3","label":"Monitor Parametros Vitais"},{"value":"4","label":"Monitor Portatil ..."},{"value":"6","label":"Compressas 20x20"},{"value":"7","label":"Ligaduras"},{"value":"10","label":"Mascara 02"},{"value":"12","label":"Soro"},{"value":"13","label":"luvas s"},{"value":"14","label":"Monitor Portatil"}]

Thanks in advange.

Answers

  • slaskskslasksk Posts: 3Questions: 1Answers: 0

    Update: now i changed 'value' to 'id', and when i click it displays correctly the label, but when i submit if sends text and not the ID

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Yup - that's the problem I always have with jQuery UI AutoComplete as well. The separation of the value and label doesn't appear to work like a normal select control. Indeed, I've actually never fully understood how that separation is meant to work in AutoComplete and is the main reason I tend to suggest Select2 for use with Editor.

    There are a number of SO threads on this issue with AutoComplete (not Editor specific - its a jQuery UI quirk) - 1, 2 and 3 for example.

    I'm strongly considering removing the jQuery UI AutoComplete plug-in from the Editor list for exactly this reason...

    Allan

  • slaskskslasksk Posts: 3Questions: 1Answers: 0

    Thanks for you help Allan, i used the value sent by the autocomplete, search for it in DB and get from there the value, not the perfect solution, but it works, hehe

This discussion has been closed.