кароч, записал записал необходимые данные в файл(.json)
потом в шаблон доьавил скрипт:
<script>
arr =[]
//alert(data);
function add(arr){
var MaxInputs = 5; //Número Maximo de Campos
var contenedor = $("#contenedor"); //ID del contenedor
var AddButton = $("#agregarCampo"); //ID del Botón Agregar
//var x = número de campos existentes en el contenedo r
var x = $("#contenedor div").length + 1;
var FieldCount = x-1; //para el seguimiento de los campos
$(AddButton).click(function (e) {
if (x==5){
FieldCount++;
$(contenedor).append('<div style="padding-top:1%"> <input id="id_spis_item-name" maxlength="300" name="spis_item-tovar5" type="text" data-provide=«typeahead» autocomplete= "off"/><a href="#" style="margin-left: 4px;" class="eliminar">×</a></div>');
$("#id_spis_item-name").autocomplete( {
source: arr,
messages: {
noResults: '',
results: function() {}
}
});
x++; //text box increment
}
if (x==4){
FieldCount++;
$(contenedor).append('<div style="padding-top:1%"> <input id="id_spis_item-url2" maxlength="300" name="spis_item-tovar4" type="text" data-provide=«typeahead» /> <a href="#" class="eliminar" style="margin: 0; paddin :0">×</a></div> ');
$("#id_spis_item-url2").autocomplete( {
source: arr,
messages: {
noResults: '',
results:'some text'
}
});
x++;
}
if (x==3){
FieldCount++;
$(contenedor).append('<div style="padding-top:1%"> <input id="id_spis_item-url1" maxlength="300" name="spis_item-tovar3" type="text" data-provide=«typeahead» /> <a href="#" class="eliminar" style="margin: 0; paddin :0">×</a></div> ');
$("#id_spis_item-url1").autocomplete( {
source: arr,
messages: {
noResults: '',
results:'some text'
}
});
x++;
}
if (x==2){
FieldCount++;
$(contenedor).append('<div style="padding-top:1%"> <input id="id_spis_item-url" maxlength="300" name="spis_item-tovar2" type="text" data-provide=«typeahead» /> <a href="#" class="eliminar" style="margin: 0; paddin :0">×</a></div> ');
$("#id_spis_item-url").autocomplete( {
source: arr,
messages: {
noResults: '',
results:'some text'
}
});
x++;
}
return false;
});
$("body").on("click",".eliminar", function(e){ //click en eliminar campo
if( x > 1 ) {
$(this).parent('div').remove(); //eliminar el campo
x--;
}
return false;
});
jQuery.fn.extend({
propAttr: $.fn.prop || $.fn.attr
});
$("#id_spis_item-tovar1").autocomplete( {
source: arr,
messages: {
noResults: '',
results:'some text'
}
});
}
$.getJSON("{% static 'js/current.json' %}", function(data) {
for (var i = 0; i < data.current.length; i++) {
arr.push(data.current[i].Description + "(" + data.current[i].ID+")");}
add(arr);
});
данный скрипт реализует добавление полей до 5 и в каждом поле при вводе чего-либо ищет схожие варианте в заранее записанном файле.
скажу сразу, скрипт не омй, я его слегка менял, но не то, тобы сильно, ибо в js почти полный ноль)