Repeat javascript cycle

2

Good evening, I have this view (the image) which is part of an invoice, precisely this is the detail of the invoice, and I have in this detail a javascript function so that while I write the name of the product I search the product in the database and when I select it I fill the input of the unit price corresponding to that product, until there all wonders, but the problem is that by pressing the + button to enter a new line and load a new product javascript function no longer works, it occurred to me that I can use a foreach or something similar to make that function work every time a new line is inserted but I can not make it work, I leave the code:  

//metodo para buscar en la base de datos
$("#inputPrecioProducto").devbridgeAutocomplete({
        showNoSuggestionNotice: true,
        serviceUrl: '/maderas/facturar/leer_productos',
        noSuggestionNotice: 'No se encontraron datos',
        onSelect: function (suggestion) {
            $('#inputIdProducto').val(suggestion.data)
            $('#inputPrecioUnidad').val(suggestion.precio_unidad);
        }
    });}


// Repetidor de campos de Productos

$('.repeater').repeater({ hide: function (deleteElement) { var elemento=$(this); swal({ title: "Estas Seguro?", text: "Se borrará toda la fila!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "Si, bórralo!", cancelButtonText: 'Cancelar', closeOnConfirm: false }, function(){ swal("Producto Borrado!", "Se ha eliminado el Producto.", "success"); elemento.remove(); sumarTotales(); crearIgv(); }); }, isFirstItemUndeletable: true }); // ./ Repetidor de campos de Productos

Thank you very much !!

    
asked by Willi Mora 06.11.2017 в 04:03
source

1 answer

1

Your problem, as specified in the comment that you have left, is that the event associated with the search is not assigned to the new field that you generate when you give the most. If you notice, in the function of your javascript that is in charge of the autocomplete, when you do the selector with JQuery you do it referring to a specific id.

$("#inputPrecioProducto").devbridgeAutocomplete({...});

To solve it I advise you to use classes to refer to the components that should have the autocomplete function. When you create the new imput, add the class: class="autocompletado" for example, and change the selector you make to refer to these inputs:

$(".autocompletado").devbridgeAutocomplete({...});

In this way, the autocomplete event will act on all the inputs that belong to the "autocomplete" class.

    
answered by 06.11.2017 в 15:44