Link to record in subform on a tab

Questions related to using nuBuilder Forte.

Link to record in subform on a tab

Unread postby treed » Tue Oct 19, 2021 2:12 am

Hello all, I'm building a "to do" list. Right now there is a browse list that shows the Organization and to do item from a related table. The way the current form works is that when the user clicks on the browse record it opens the organization record and the user has to go to the to do tab and find the record in question in the sub form. The way I would like it to work is that clicking on the browse record, the to do item is opened in the subform. Is this possible?
treed
 
Posts: 102
Joined: Mon May 18, 2020 7:32 am

Re: Link to record in subform on a tab

Unread postby kev1n » Tue Oct 19, 2021 4:32 pm

treed wrote: The way I would like it to work is that clicking on the browse record, the to do item is opened in the subform. Is this possible?


Would it suffice if the to-do tab is opened and then the record in the subform focused/highlighted?
kev1n
nuBuilder Team
 
Posts: 2135
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Link to record in subform on a tab

Unread postby treed » Thu Oct 21, 2021 7:08 am

That would be perfect!
treed
 
Posts: 102
Joined: Mon May 18, 2020 7:32 am

Re: Link to record in subform on a tab

Unread postby kev1n » Fri Oct 22, 2021 3:41 am

Add the Primary Key column of the to-do item to the Browse form (column width 0 to hide it).

In the form's Custom Code add this JavaScript code.
Replace some values as indicated in the code

Code: Select all
function nuSelectBrowse(e) {

    let pk = $('#' + e.target.id).attr('data-nu-primary-key');
    let row   = $('#' + e.target.id).attr('data-nu-row');
   
   let pkColumn = '0';  // <------ Change: Column number of the to-do's primary key. 0 = first column, 1 = 2nd column etc.
   
   window.pkToDo   = $('#nucell_' + row + '_' + pkColumn).html();   
   
   nuForm(nuGetProperty('form_id'), pk, '', '', '0');

}


if (nuFormType() == 'edit') {

   if (window.pkToDo !== undefined) {
   
      nuSelectTab($('#nuTab1')[0]);  // <------ Select the 2nd tab. nuTab2 would be the 3rd tab etc.
      subFromHighlightRow('subform_id', window.pkToDo); // <------- Replace subform_id with the object Id of the subform
      window.pkToDo = undefined;
   
   }
}   

function subFromHighlightRow(sfId, pk) {
   
    var sf = nuSubformObject(sfId);   
    for (var i = 0; i < sf.rows.length; i++) {
            if (sf.rows[i][0] == pk) {
             var c = $('#' + sfId + nuPad3(i) + nuSubformObject(sfId).fields[1]);
            c.css('color','#EC7063').focus();
            return;
         }
           
        }
}
kev1n
nuBuilder Team
 
Posts: 2135
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Link to record in subform on a tab

Unread postby kev1n » Wed Nov 10, 2021 3:04 pm

Hi, just wanted to follow up on this. Were you able to make it work?
kev1n
nuBuilder Team
 
Posts: 2135
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5


Return to General

Who is online

Users browsing this forum: No registered users and 19 guests