Page 1 of 1
Cascade select in subform
Posted: Sun Jul 30, 2023 10:44 pm
by calida82
Hi I would like to know if it is possible to use cascade select in a subform. subform displayed in edit mode.
how can i move the label above the object
Re: Cascade select in subform
Posted: Sun Aug 06, 2023 11:00 am
by kev1n
Hi,
There's an example somewhere in the forum for a subform in Grid mode. I haven't tried that approach for Type "Form".
Re: Cascade select in subform
Posted: Sat Aug 12, 2023 7:06 am
by calida82
hi, i found the post you are talking about and i am trying that solution
https://forums.nubuilder.cloud/viewtopic.php?t=11249
I managed to get it working by adapting the code to my app's field names but I have a problem when I open a record that already has lines filled in the subform. Both the first and second select show the previously saved data but if I try to change the value of the second select without changing the first I get the complete list and not the data related to the first select. instead I modify first select and then the second everything works.
foto.png
in the picture ignore the lookup icon is not used...
this is the main form code
Code: Select all
function nuSubformRefreshSelectObject(prefix, selectId, formId, removeBlank) {
if (typeof formId === 'undefined') {
var formId = '';
}
nuSetProperty('nurefreshselectobject_prefix',prefix);
nuSetProperty('nurefreshselectobject_selectid',selectId);
nuSetProperty('nurefreshselectobject_formid',formId);
nuSetProperty('nurefreshselectobject_removeblank',removeBlank === true ? '1' : '0');
nuRunPHPHidden('nurefreshselectobject', 0);
}
function nuSubformPrefix(t, id){
return $(t).attr('data-nu-prefix');
}
function pne_marcaOnChanged(t) {
nuSetProperty('VALUE_SELECT1',nuSubformValue(t, 'pne_marca'));
nuSubformRefreshSelectObject(nuSubformPrefix(t, 'pne_marca'), 'pne_modello', '64d287f80aea206'); // <---- Replace with the the subform's primary key (15-characters unique id)
let pne_modello = t.id.replace('pne_marca','pne_modello');
$('#'+ pne_modello).nuEnable();
}
$('[id^=Sf_pneumatici][id$=pne_modello]').each(function(i,v){ // <---- replace 'subform' with the object id of your subform
$(this).attr('data-value', this.value);
});
$('[id^=Sf_pneumatici][id $=pne_marca]').each(function(i,v){ // <---- replace 'subform' with the object id of your subform
pne_marcaOnChanged(this)
});
function nuBeforeSave() {
nuSetProperty('VALUE_SELECT1','##');
return true;
}
function nuSelectObjectRefreshed(formId, selectId, count) {
let pne_modello = selectId.replace('pne_marca','pne_modello');
$('#'+ pne_modello).val($('#' + pne_modello).attr('data-value'));
}
this is sql from the second select
Code: Select all
SELECT
t_modelli.mod_modello,t_modelli.mod_modello
FROM
t_modelli
JOIN t_marche ON t_modelli.mod_id_marca = t_marche.mar_id
WHERE
(t_marche.mar_marca = '#VALUE_SELECT1#' OR '#VALUE_SELECT1#' LIKE '#%' );
this is the onChange event of the first select
Where am I doing wrong?
Re: Cascade select in subform
Posted: Wed Aug 16, 2023 1:40 pm
by kev1n
Hi,
I will look into it soon. I'm currently busy with other things.
Re: Cascade select in subform
Posted: Wed Aug 16, 2023 2:52 pm
by calida82
hello, ok, I have to finish my webapp and for the moment I have opted for a lookup that takes data from 2 different tables and fills in the two fields of the subform.