0
I have a screen where there is an auto-complete for sale items, the user searches the item by name or code, so far everything works.
I need to capture the chosen item and send it to backend (Django) to save to a JSON file. The idea is to have a JSON for each account.
But I don’t know how to send the inputs
to the backend so that you can record this to a file, since I will upload that same file to fill a table
of the chosen registered items.
This is my autocomplete code.
$(function() {
$("#itemsearch").autocomplete({
source: "/menus/autocomplete_search/",
select: function (event, ui)
{
AutoCompleteSelectHandler(event, ui)
{
ui.item.value = "";
}
},
minLength: 1,
});
});
var result = 0
var price = 0
function AutoCompleteSelectHandler(event, ui)
{
var selectedObj = ui.item;
var name = selectedObj.value
var codigo = selectedObj.item_num
price = selectedObj.item_price
var table = document.getElementById('tableItemVenda');
var row = table.insertRow(1);
row.innerHTML = "<td>"+codigo+"</td> <td>"+name+"</td> <td>R$ "+price+"</td>";
inserirTotal(price);
}
What does chosen mean? Select on the page? Submit a form? This will determine which event you will call and the time you call the backend to record the selection
– Leonardo Pessoa
@Leonardopessoa the selected item is the ui.item of the autocomplete. It works like this, when typing the name or code, the(s) items appear in the autocomplete dropdown list, to choose the item, the user navigates with the arrows and press enter on the item you want.
– Rodolfo Sousa