Page 1 of 1

Browse/edit form as subform

Posted: Sun Dec 01, 2024 9:26 pm
by elbrownos
Hi All

I'm new to nuBuilder (and web development in general) so hopefully this is an easy question.
I'd like to create a browse-edit form that acts as a subform of another browse/edit form.
Say there are Projects, and each project has items of equipment, and each item of equipment has components.
So I have a browse/form called Projects. In the Project edit form I have a button that opens another browse/edit form called Equipment. And in the Equipment edit form I have another button that opens Components.
How do I make it so that the Equipment form only includes items relating to the Project that it is under, and the Component form only includes items relating to the Equipment that it is under?

Thanks in advance.

Re: Browse/edit form as subform

Posted: Sun Dec 01, 2024 10:22 pm
by steven
Hi elbrownos,

Can you share a copy of you database or provide some screen shots?


Steven

Re: Browse/edit form as subform

Posted: Mon Dec 02, 2024 12:06 am
by kev1n
Use Hash Cookies as described here.

Re: Browse/edit form as subform

Posted: Tue Dec 03, 2024 3:08 am
by elbrownos
Hi, thanks for your help. Sorry I couldn't follow how to use hash cookies to do this.
I've attached my database.
The first option uses iframes, the second uses buttons. I would prefer to get the buttons option working.
The behaviour I'm trying to implement is:
If I go into Projects and create two projects (say "Project 1" & "Project 2").
Then from "Project 1" I create an equipment "Project 1 Equipment 1" and from "Project 2" I create "Project 2 Equipment 1"
When I go into a project I only want to be able to see the equipment that belongs to that project.
Likewise for a further level of "Components" that belong to "Equipment"
Hope that makes sense.

Re: Browse/edit form as subform

Posted: Tue Dec 03, 2024 10:02 pm
by elbrownos
Perhaps a simpler question -
A subform table has a foreign key field for the master record ID.
What is the mechanism for the master record ID to be copied to the subform foreign key ID, and what is the mechanism for the subform to only display records where the foreign key ID matches the master record ID?
This is the behavior I want to duplicate with browse/edit forms.

Re: Browse/edit form as subform

Posted: Tue Dec 03, 2024 10:24 pm
by nc07
elbrownos wrote: Tue Dec 03, 2024 10:02 pm Perhaps a simpler question -
A subform table has a foreign key field for the master record ID.
What is the mechanism for the master record ID to be copied to the subform foreign key ID, and what is the mechanism for the subform to only display records where the foreign key ID matches the master record ID?
This is the behavior I want to duplicate with browse/edit forms.
Hy, you could do some thing like this; in the Js of browse/ edit form of child form, use the below code, replace the brdngn_id with the id of your foreign key ie. field that will hold your parent id.

Code: Select all

var parentid = parent.nuCurrentProperties().record_id;
 if ($('#brdngn_id').val() ===''){
        $('#brdngn_id').val(parentid).change();
        
    }
hope this helps.

Regards
Nilesh

Re: Browse/edit form as subform

Posted: Wed Dec 04, 2024 10:36 am
by elbrownos
Thanks Nilesh! it works if my child form is an iFrame.
How would I do the same thing if my child form is opened via a button?

Re: Browse/edit form as subform

Posted: Wed Dec 04, 2024 6:41 pm
by steven
Hi elbrownos,

Change the SQL to include Hash Cookies - as kev1n mentioned.

Code: Select all

SELECT * FROM Equipment
WHERE eqp_equipment_short_code like '#prj_project_short_code#%'

equip.png

And you'll get this...

after.png


Steven

Re: Browse/edit form as subform

Posted: Sun Dec 08, 2024 11:55 pm
by nc07
elbrownos wrote: Wed Dec 04, 2024 10:36 am Thanks Nilesh! it works if my child form is an iFrame.
How would I do the same thing if my child form is opened via a button?
you can can create a function and call it on onclick event of the button;

Code: Select all


  function addnewreadings() {
    var rid = nuCurrentProperties().record_id;
    if (rid === '' || rid === '-1') {
        alert('Please save the fumigation details first before updating the Concentration reading');
        return;
        //nuSaveAction();

    } else {
        sessionStorage.setItem("fum_id", rid);
        nuPopup('64f6912de704de1', '-1', '', '');

    }
}

function newreading() {
    nuPopup('64f6912de704de1', '-1', '', '');

}
and in the popup form you can retrieve the Parent key like this:

Code: Select all

if (nuFormType() === 'edit') {
    // Set address if opened from an address
    var refA = sessionStorage.getItem("fum_id");
    console.log(refA);

    if (refA !== null && refA !== '-1') {
        $('#fumigations_id').val(refA).change();
    } else {
        nuClosePopup(parent.nuGetBreadcrumb());
    }
}

Hope this works for you, make necessary changes according to your needs.

Re: Browse/edit form as subform

Posted: Fri Dec 13, 2024 7:45 am
by elbrownos
Thanks for your help everyone, I've got it working how I wanted.