Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Cascade select in subform

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Cascade select in subform

Unread post 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
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Cascade select in subform

Unread post 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".
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Cascade select in subform

Unread post 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

Code: Select all

pne_marcaOnChanged(this);
Where am I doing wrong?
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Cascade select in subform

Unread post by kev1n »

Hi,

I will look into it soon. I'm currently busy with other things.
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Cascade select in subform

Unread post 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.
Post Reply