-
Notifications
You must be signed in to change notification settings - Fork 0
/
formulario.js
62 lines (49 loc) · 1.39 KB
/
formulario.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*-----------------------------------------------*\
GLOBAL VARIABLES
\*-----------------------------------------------*/
var url_almacenes = window.location.origin + "/api/almacenes/"
/*-----------------------------------------------*\
LOAD
\*-----------------------------------------------*/
$(document).ready(function () {
formulario = new TargetaFormulario()
})
/*-----------------------------------------------*\
OBJETO: Targeta Formulario
\*-----------------------------------------------*/
function TargetaFormulario(){
this.$almacenes = $('#id_almacenes')
this.init()
}
TargetaFormulario.prototype.init = function () {
var csrftoken = $("[name=csrfmiddlewaretoken]").val()
this.$almacenes.select2(
{
language: "es",
//minimumInputLength: 1,
}
)
$.ajax(
{
url: url_almacenes,
headers: { "X-CSRFToken": csrftoken },
data: function (params) {
return {
id: params.id, // search term
clave: params.clave,
descripcion: params.descripcion
}
},
dataType:"json",
type:"GET"
}
).done(function(data)
{
$.each(data, function(index, item)
{
$("#id_almacenes").append($('<option>').attr('value',item.pk).text(item.clave+"–"+item.descripcion))
}
)
}
)
}