arreglado los select2 para que funcionen con el select2 de alvaro

This commit is contained in:
2024-10-14 14:29:43 +02:00
parent 44fc60372b
commit 9c3a7848f3
4 changed files with 37 additions and 6 deletions

View File

@ -370,6 +370,7 @@ $routes->group('clientes', ['namespace' => 'App\Controllers\Clientes'], function
$routes->get('delete/(:num)', 'Cliente::delete/$1', ['as' => 'clienteDelete']);
$routes->post('datatable', 'Cliente::datatable', ['as' => 'clienteDT']);
$routes->post('menuitems', 'Cliente::menuItems', ['as' => 'menuItemsOfClientes']);
$routes->get('getSelect2', 'Cliente::getSelect2', ['as' => 'getListaSelect2']);
});
});

View File

@ -330,6 +330,30 @@ class Cliente extends \App\Controllers\BaseResourceController
}
public function getSelect2()
{
if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getGet('searchTerm'))[0];
$reqId = goSanitize($this->request->getGet('id'))[0];
$reqText = goSanitize($this->request->getGet('text'))[0];
$onlyActiveOnes = false;
$columns2select = [$reqId ?? 'id', $reqText ?? 'nombre'];
$onlyActiveOnes = false;
try{
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
}
catch(Exception $e){
$menu = [];
}
$menu,
return $this->respond($menu);
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
protected function getPaisListItems($selId = null)
{
$paisModel = model('App\Models\Configuracion\PaisModel');

View File

@ -4,9 +4,11 @@
* @param {String} url
* @param {String} placeholder
*/
let ClassSelect = function (domItem, url, placeholder, allowClear = false) {
let ClassSelect = function (domItem, url, placeholder, allowClear = false, params = {}) {
this.url = url;
this.item = domItem;
this.params = params;
this.config = {
placeholder: placeholder,
allowClear: allowClear,
@ -15,10 +17,14 @@ let ClassSelect = function (domItem, url, placeholder, allowClear = false) {
url: () => {
return this.url;
},
data: function (params) {
return {
q: $.trim(params.term),
};
data: (params) => {
let d = $.trim(params.term);
for (let key in this.params) {
d[key] = this.params[key];
}
return d;
},
processResults: function (data) {
return {

View File

@ -10,7 +10,7 @@ class DatosGenerales {
this.validatorStepper = validatorStepper;
this.formatoLibro = new ClassSelect($("#papelFormatoId"), '/papel-formato/menuitems', window.translations["formatoLibro"]);
this.cliente = new ClassSelect($("#clienteId"), '/clientes/cliente/menuitems', window.translations["selectCliente"]);
this.cliente = new ClassSelect($("#clienteId"), '/clientes/cliente/getSelect2', window.translations["selectCliente"]);
this.titulo = this.domItem.find("#titulo");