Greetings,
The functionality I'm looking for is something that I thought I remembered doing in NuBuilderPro but I can't seem to figure it out in Forte.
I have a Browse Form used to select an item, and I want to pass the key for that item into a second Browse Form, having it end up in the WHERE clause in the SQL query for the second Browse Form. This is similar to what happens automatically for Subforms, but in Forte those are only Edit Forms and not Browse Forms. I could use a Run iFrame, but so far I haven't figured out how to pass the key into it. Maybe with a hash cookie?
I have lots of SQL and other programming experience, but relatively little PHP or Javascript! All assistance gratefully accepted.
Thanks,
--Douglas
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
How do I make a subform behave as a Browse, not an Edit form?
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: How do I make a subform behave as a Browse, not an Edit form?
Hi,
What should happen when a row of the 1st Browse is clicked? Should the 2nd browse opened in the same breadcrumb or another tab?
What should happen when a row of the 1st Browse is clicked? Should the 2nd browse opened in the same breadcrumb or another tab?
-
- Posts: 6
- Joined: Sun Dec 17, 2017 9:09 am
- Location: San Francisco, California
- Has thanked: 1 time
Re: How do I make a subform behave as a Browse, not an Edit form?
Either one would work, but I suppose another tab might be even more useful, particularly if previousy-clicked rows remained in open tabs, but this isn't essential.
I'm working on an application to track real estate construction and repair, and the app contains a simple accounting core within it. What I was trying to do here was to click on an account from the chart of accounts, and use the account ID to select the list of transactions associated with that account to display a register including a running balance. Being able to have the tabs for previously opened account registers stick around would be handy but not essential. The challenge with using an edit form as a grid is I don't see how to compute the running balance under those circumstances. With a browse form, it's easy using SQL.
This same pattern would be used to track lists of anything within the project-- material, labor, whatever, but those could most likely use the grid subform.
Incidentially, I had this app nearly finished in NuBuilderPro a number of years ago, but was running into some problems, and then NuBuilderForte came out. Since there wasn't an easy upgrade path, I put the project on the shelf as I had other projects to do. Now I'm back to re-writing it in Forte.
I'm working on an application to track real estate construction and repair, and the app contains a simple accounting core within it. What I was trying to do here was to click on an account from the chart of accounts, and use the account ID to select the list of transactions associated with that account to display a register including a running balance. Being able to have the tabs for previously opened account registers stick around would be handy but not essential. The challenge with using an edit form as a grid is I don't see how to compute the running balance under those circumstances. With a browse form, it's easy using SQL.
This same pattern would be used to track lists of anything within the project-- material, labor, whatever, but those could most likely use the grid subform.
Incidentially, I had this app nearly finished in NuBuilderPro a number of years ago, but was running into some problems, and then NuBuilderForte came out. Since there wasn't an easy upgrade path, I put the project on the shelf as I had other projects to do. Now I'm back to re-writing it in Forte.
--Douglas Mandell
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: How do I make a subform behave as a Browse, not an Edit form?
In nuBuilder Forte, you can override the nuSelectBrowse(event) function to get the primary key of the selected row and perform your custom actions. Here's how you can do that:
1. Create a hash cookie to store the selected value:
In the first Browse Form, add a Custom Code with the following JavaScript:
This code will override the default nuSelectBrowse(event) function. When you click on a row in the first Browse Form, the function will find the closest tr element to the clicked element, get the primary key from the data- attribute. Then the selected primary key is stored in a Hash Cookie and the 2nd Browse form is opened.
2. Modify the second Browse Form's SQL query:
In the second Browse Form, modify the SQL query to include the WHERE clause with the stored value from the hash cookie.
Replace your_table and your_key_column with the appropriate table and column names from your database.
Now, when you click the custom button in the first Browse Form, it will store the selected row's key in a hash cookie and open the second Browse Form, filtering the results based on the stored key.
1. Create a hash cookie to store the selected value:
In the first Browse Form, add a Custom Code with the following JavaScript:
Code: Select all
function nuSelectBrowse(e) {
const cell = $(e.target).closest('div'); // Find the closest div/cell to the clicked element
const primaryKey = cell.attr('data-nu-primary-key'); // Get the row's primary Key
nuSetProperty('selected_item_id', primaryKey); // Save the selected ID in a hash cookie
nuForm('6b4f921bb31e163', '', '', '', '1'); // Open the other Browse form in the same Tab. Replace 6b4... with your form Id
}
2. Modify the second Browse Form's SQL query:
In the second Browse Form, modify the SQL query to include the WHERE clause with the stored value from the hash cookie.
Code: Select all
SELECT *
FROM your_table
WHERE your_key_column = '#selected_item_id#'
Replace your_table and your_key_column with the appropriate table and column names from your database.
Now, when you click the custom button in the first Browse Form, it will store the selected row's key in a hash cookie and open the second Browse Form, filtering the results based on the stored key.
-
- Posts: 6
- Joined: Sun Dec 17, 2017 9:09 am
- Location: San Francisco, California
- Has thanked: 1 time
Re: How do I make a subform behave as a Browse, not an Edit form?
OK, I'm getting closer!
I wasn't sure what you meant by "add a custom button", but I added the above function to Custom Code / Browse & Edit for to first Browse Form, and clicking on a row in the form does now bring up the second Browse form, but the selected row's primary key isn't ending up in the variable primaryKey. The second Browse form ends up with no data. However, if, for testing, I manually substitute the ID of a known row from the first form using, for example:
nuSetProperty('selected_item_id', '640d50de1ec4dce');
then the second browse forms select does correctly end up with all entries belonging to that id. This tells me that the hash cookie is getting through to the second browse, but that in the custom code it isn't picking up the selected row's primary key.
So what am I doing wrong?
Thanks!
I wasn't sure what you meant by "add a custom button", but I added the above function to Custom Code / Browse & Edit for to first Browse Form, and clicking on a row in the form does now bring up the second Browse form, but the selected row's primary key isn't ending up in the variable primaryKey. The second Browse form ends up with no data. However, if, for testing, I manually substitute the ID of a known row from the first form using, for example:
nuSetProperty('selected_item_id', '640d50de1ec4dce');
then the second browse forms select does correctly end up with all entries belonging to that id. This tells me that the hash cookie is getting through to the second browse, but that in the custom code it isn't picking up the selected row's primary key.
So what am I doing wrong?
Thanks!
--Douglas Mandell
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: How do I make a subform behave as a Browse, not an Edit form?
I updated the nuSelectBrowse() function above.