Skip to content

Commit

Permalink
Correcciones para los formularios de edición
Browse files Browse the repository at this point in the history
El uso del componente rup_select ocasionaba problemas a la hora de definir los valores obtenidos en la petición GET que rellena los campos en una edición.

También se ha corregido un problema que evitaba que los rup_select fueran restaurados a su valor por defecto cuando se pasaba de una edición a un alta.

(cherry picked from commit fbcf342)
  • Loading branch information
xaabi6 committed Apr 29, 2024
1 parent 31a4663 commit 5b724a9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/rup.form.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,12 @@
*/
clearFields: function (includeHidden) {
return this.each(function () {
var ruptype = $(this).attr('ruptype');
const ruptype = $(this).attr('ruptype');

if (ruptype === undefined || ruptype !== 'combo') {
if (ruptype === undefined || ruptype !== 'select' ) {
$(this).clearFields(includeHidden);
} else {
$(this).rup_combo('clear');
} else if (ruptype === 'select') {
$(this).rup_select('clear');
}
});
},
Expand Down
35 changes: 20 additions & 15 deletions src/rup.select.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,16 +738,16 @@
* $("#idSelect").rup_select("search", "java");
*/
search: function (term,notOthersClose) {
let $search = $(this).data('select2').dropdown.$search ||$(this).data('select2').mySelect.selection.$search;
let $search = $(this).data('select2').dropdown.$search || $(this).data('select2').mySelect.selection.$search;
if(!notOthersClose){
$('.select2-hidden-accessible').select2('close');
}
$(this).data('select2').$container.find('input').val(term);
if($search != undefined){
$search.val(term);
$search.trigger('keyup');
$search.val(term);
$(this).data('settings').selected = term;
$search.trigger('keyup');
}

},
/**
* Permite consultar y modificar la configuración del componente.
Expand Down Expand Up @@ -1231,7 +1231,7 @@
success(__cache[__cachekey]);
// Actualizar seleccionado en la lista//css
let positions = [];
let valueSelect = $('#' + settings.id).rup_select('getRupValue');
let valueSelect = settings.selected ? settings.selected : $('#' + settings.id).rup_select('getRupValue');

if(settings.groups){// Parseo de grupos para
// seleccionar
Expand All @@ -1254,16 +1254,21 @@
}
//Se obliga a que las claves sean String recomendado por select2
let seleccionado = $.grep(data, function (v,index) {
v.id = String(v.id);
if (v.text === undefined && v[settings.sourceParam.text] !== undefined) {
v.text = v[settings.sourceParam.text];
}

if(v.id == valueSelect){
positions.push(index);
}
return v.nid == settings.selected || v.id == settings.selected;
});
if (v.id === undefined && v[settings.sourceParam.id] !== undefined) {
v.id = String(v[settings.sourceParam.id]);
} else {
v.id = String(v.id);
}

if (v.text === undefined && v[settings.sourceParam.text] !== undefined) {
v.text = v[settings.sourceParam.text];
}

if (v.id == valueSelect) {
positions.push(settings.blank == "" ? index - 1 : index);
}
return v.id == settings.selected;
});
if( $('#' + settings.id).rup_select('getRupValue') != ''){
seleccionado = $.grep(data, function (v) {
return v.id == $('#' + settings.id).rup_select('getRupValue');
Expand Down
3 changes: 3 additions & 0 deletions src/rup.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@
$arbol[selectorArray] = tree_data;
formElem.on('loaded.jstree', loadedJstreeEvent);

} else if(formElem.attr('ruptype') === 'select') {
// Necesario invocar al método search que por detrás se encargará de llamar a setRupValue.
formElem['rup_' + formElem.attr('ruptype')]('search', aData[i]);
} else {
// Forma de evitar el EVAL
formElem['rup_' + formElem.attr('ruptype')]('setRupValue', aData[i]);
Expand Down
9 changes: 5 additions & 4 deletions src/rup_table/rup.table.editForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,11 @@
});
} else {
// Para cuando el formulario actual sigue siendo válido (ya sea dinámico o no)
let deferred = $.Deferred();
ctx.oInit.formEdit.actionType = actionType;
deferred.resolve();
return deferred.promise();
let deferred = $.Deferred();
ctx.oInit.formEdit.actionType = actionType;
$(ctx.oInit.formEdit.idForm).rup_form('clearForm', true);
deferred.resolve();
return deferred.promise();
}
}

Expand Down

0 comments on commit 5b724a9

Please sign in to comment.