mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
añadidos los ficheros
This commit is contained in:
64
httpdocs/assets/js/safekat/components/select2.js
Normal file
64
httpdocs/assets/js/safekat/components/select2.js
Normal file
@ -0,0 +1,64 @@
|
||||
class ClassSelect2 {
|
||||
|
||||
constructor(domItem, url, placeholder = "", delay = 60, text_field = 'nombre', id_field = 'id') {
|
||||
this.domItem = domItem;
|
||||
this.url = url;
|
||||
this.placeholder = placeholder;
|
||||
this.delay = delay;
|
||||
this.text_field = text_field;
|
||||
this.id_field = id_field;
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
this.domItem.select2({
|
||||
allowClear: false,
|
||||
placeholder: this.placeholder,
|
||||
ajax: {
|
||||
url: this.url,
|
||||
type: 'post',
|
||||
dataType: 'json',
|
||||
data: (params) => {
|
||||
|
||||
return {
|
||||
id: this.id_field,
|
||||
text: this.text_field,
|
||||
searchTerm: params.term,
|
||||
};
|
||||
},
|
||||
delay: this.delay,
|
||||
processResults: function (response) {
|
||||
|
||||
return {
|
||||
results: response.menu
|
||||
};
|
||||
},
|
||||
cache: true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Método para obtener el valor seleccionado
|
||||
getValue() {
|
||||
return this.domItem.val();
|
||||
}
|
||||
|
||||
// Método para establecer el valor seleccionado
|
||||
setValue(value) {
|
||||
this.domItem.val(value).trigger('change');
|
||||
}
|
||||
|
||||
// Método para oculatar el select2
|
||||
hide() {
|
||||
console.log(this.domItem);
|
||||
this.domItem.select2('close');
|
||||
this.domItem.next('.select2-container').hide();
|
||||
}
|
||||
|
||||
// Método para mostrar el select2
|
||||
show() {
|
||||
this.domItem.next('.select2-container').show();
|
||||
}
|
||||
}
|
||||
|
||||
export default ClassSelect2;
|
||||
Reference in New Issue
Block a user