Feed hash variable between two iFrames

Questions related to customising nuBuilder Forte with JavaScript or PHP.

Feed hash variable between two iFrames

Unread postby nickrth » Thu Jul 08, 2021 2:32 pm

I'm hoping someone might be able to help point me in the right direction.

I have two iFrames on a form, both showing a browse form. What I want to happen is when you select and item on the left iFrame, it filter the records in the right iFrame accordingly. In the attached example pic, when you click "Bacon sliced" on the left, I want to to show just three records for that item on the right. I can filter the iFrame on the right with a hash variable no worries, I'm just having trouble setting the variable from the left iFrame and then reading it in the right one.

Thanks in advance!
Attachments
CAKE_-_Recipe_planning.png
CAKE_-_Recipe_planning.png (69.27 KiB) Viewed 311 times
nickrth
 
Posts: 19
Joined: Sun Aug 23, 2020 10:49 pm

Re: Feed hash variable between two iFrames

Unread postby kev1n » Thu Jul 08, 2021 3:12 pm

Add a nuSelectBrowse() in the left iFrame's Custom Code.

Replace iframe_id with your right iFrame Id
Replace some_hash_ccookie with the Hash Cookie name

Code: Select all
function nuSelectBrowse(e) {

    var r = $(e.target).attr('data-nu-primary-key'); // retrieve the primary key of the selected cell, assuming that both browse forms share the same primary key.
   if (r !== '') {
      var f = $("#iframe_id")[0].contentWindow; // Get a reference to the iFrame
      f.nuSetProperty('some_hash_ccookie', r); // set a Hash Cookie that can be used in SQL
      f.nuGetBreadcrumb(); // refresh the iFrame
   }

    return false;
}


kev1n
nuBuilder Team
 
Posts: 2012
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Feed hash variable between two iFrames

Unread postby nickrth » Thu Jul 08, 2021 4:09 pm

Thank you so much for your help kev1n. I must be doing something really silly...

I assume that I put that nuSelectBrowse function on the form properties for the iFrame rather than an 'onclick' custom code for the run object containing the iFrame?

Here are all my settings...

Left iFrame
Form ID: 60e670aad718b55
Table name: veventrecipes
Primary key: recipe_id
Browse:
Code: Select all
SELECT veventrecipes.*
FROM veventrecipes
GROUP BY veventrecipes.item_id ASC
ORDER BY veventrecipes.item_name ASC

Custom code:
Code: Select all
function nuSelectBrowse(e) {

    var r = $(e.target).attr('data-nu-primary-key'); // retrieve the primary key of the selected cell, assuming that both browse forms share the same primary key.
   if (r !== '') {
      var f = $("#60e6611fbfda069")[0].contentWindow; // Get a reference to the iFrame
      f.nuSetProperty('filter_item_id', r); // set a Hash Cookie that can be used in SQL
      f.nuGetBreadcrumb(); // refresh the iFrame
   }

    return false;
}


Right iFrame
Form ID: 60e6611fbfda069
Table name: veventrecipes
Primary key: recipe_id
Browse:
Code: Select all
SELECT veventrecipes.*
FROM veventrecipes
WHERE veventrecipes.item_id ='#filter_item_id#'
GROUP BY veventrecipes.dish_id ASC, veventrecipes.item_id ASC
ORDER BY veventrecipes.item_name ASC


When I click on an item in the left iFrame, it doesn't look like it's trying to refresh the iFrame on the right (ie there's no screen redraw happening).

Any ideas what I'm doing wrong?

Thank you so much for your help.
nickrth
 
Posts: 19
Joined: Sun Aug 23, 2020 10:49 pm

Re: Feed hash variable between two iFrames

Unread postby kev1n » Thu Jul 08, 2021 4:13 pm

Use the Run Object ID instead of the Form ID (60e6611fbfda069)
kev1n
nuBuilder Team
 
Posts: 2012
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Feed hash variable between two iFrames

Unread postby nickrth » Thu Jul 08, 2021 4:27 pm

So now I have:
Code: Select all
function nuSelectBrowse(e) {

    var r = $(e.target).attr('data-nu-primary-key'); // retrieve the primary key of the selected cell, assuming that both browse forms share the same primary key.
   if (r !== '') {
      var f = $("#item_recipes_sub")[0].contentWindow; // Get a reference to the iFrame
      f.nuSetProperty('filter_item_id', r); // set a Hash Cookie that can be used in SQL
      f.nuGetBreadcrumb(); // refresh the iFrame
   }

    return false;
}


But still no dice... Can't work out what I'm doing wrong.
Attachments
CAKE_-_Recipe_planning.png
CAKE_-_Recipe_planning.png (122.48 KiB) Viewed 303 times
nickrth
 
Posts: 19
Joined: Sun Aug 23, 2020 10:49 pm

Re: Feed hash variable between two iFrames

Unread postby nickrth » Thu Jul 08, 2021 4:51 pm

I think I might have an idea as to what the problem is.

Both iFrames refer to the same table (view) and therefore both have the same primary key (recipe_id), but I need to filter the right hand iFrame where the item_id = the hash cookie, not where the primary key = the hash cookie.

So maybe needs a slightly different approach?

I think in need the variable 'r' to return the item_id rather than the PK (recipe_id). But I can't quite work out how to do that.
Last edited by nickrth on Thu Jul 08, 2021 4:53 pm, edited 1 time in total.
nickrth
 
Posts: 19
Joined: Sun Aug 23, 2020 10:49 pm

Re: Feed hash variable between two iFrames

Unread postby kev1n » Thu Jul 08, 2021 4:52 pm

write:

Code: Select all
      var f = parent.$("#item_recipes_sub")[0].contentWindow; // Get a reference to the iFrame
kev1n
nuBuilder Team
 
Posts: 2012
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Feed hash variable between two iFrames

Unread postby nickrth » Thu Jul 08, 2021 10:46 pm

Woohoo!! It's working. Thanks so much kev1n! :D

While I'm at it, don't suppose you have a solution for highlighting the row that's been selected in the left browse form?
nickrth
 
Posts: 19
Joined: Sun Aug 23, 2020 10:49 pm

Re: Feed hash variable between two iFrames

Unread postby kev1n » Thu Jul 08, 2021 11:41 pm

Code: Select all
function nuSelectBrowse(e) {

    var pk = $(e.target).attr('data-nu-primary-key'); // retrieve the primary key of the selected cell, assuming that both browse forms share the same primary key.
    if (pk !== '') {

        // Color the selected row
        var row = $(e.target).attr('data-nu-row');
        $("DIV[id^='nucell']").css("color", 'black'); // reset to black
        $('[data-nu-row="' + row + '"]').css("color", 'red'); // color the selected row

        // Refresh the Recipes iframe
        var f = parent.$("#item_recipes_sub")[0].contentWindow; // Get a reference to the iFrame
        f.nuSetProperty('filter_item_id', pk); // set a Hash Cookie that can be used in SQL
        f.nuGetBreadcrumb(); // refresh the iFrame
    }

    return false;
}
kev1n
nuBuilder Team
 
Posts: 2012
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Feed hash variable between two iFrames

Unread postby nickrth » Fri Jul 09, 2021 5:03 pm

kev1n you're an absolute legend!! It works perfectly. Thank you so much.
nickrth
 
Posts: 19
Joined: Sun Aug 23, 2020 10:49 pm


Return to Custom Code

Who is online

Users browsing this forum: No registered users and 6 guests

cron