Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Open a form via a Button

Post Reply
Fundi
Posts: 27
Joined: Sun Apr 17, 2011 10:22 pm

Open a form via a Button

Unread post by Fundi »

Hi
I created a subform on a Form. I created in the detail row apart from other fields a button to open a related form. Since each row in the subform is going to display this button it would be helpful to not just open the search form but the associated form with the objects and display the corresponding record.

I tried to work with the "Default Filter for Browse Screen" but it does not accept the '#id#' variable. I also tried with the "Record ID" although I can put a manually a number and then it works but it must be the value of the '#id#' variable of the current record in the subform.

If this could work it would be a great benefit for the User. Thanks in advance to anyone looking into this.

Fundi
Fundi
Posts: 27
Joined: Sun Apr 17, 2011 10:22 pm

Re: Open a form via a Button

Unread post by Fundi »

Hi all
In the last few days I have been looking at every single sample database app I could find and low and behold the same functionality is on the payments screen of the invoicing system database. Thank for whoever made this application.

The buttons in the sub-form hold this code:

Code: Select all

 var PRE = this.name.substring(0,21);
invType   = document.getElementById(PRE +'tra_type').value;
Now it seems to me this is php code (although there is no <php php> tags around it.

It is great that we can use such code. What puzzles me though is the use of the variables. How can I find out what variables are available to me in a given sub-form?
I would be very appreciative if someone would be able to shed some light on this code. Perhaps an article with some info would be very useful for the wiki as part of the documentation.
Fundi
Posts: 27
Joined: Sun Apr 17, 2011 10:22 pm

Re: Open a form via a Button

Unread post by Fundi »

Ok, Ok so now I got the heck of this. Only 4 hours of research! :geek:

Firs tof all the code posted above was only a fraction of it and actually that part was irrelevant to what I wanted to do.

To open a from from a button this is how it works (and please correct me if I am wrong).
1. Don't but anything in the fields of the button tab for the button except the width of the button. (if you put a form it should open it will go to the browse screen).
2. In the Double click event field my java-script code is as follows:

Code: Select all

var PRE = this.name.substring(0,8);
event_ID = document.getElementById(PRE +'id').value;
openForm('14db1a2eb6bde8',event_ID );
The following is an attempt of an explanation:
1. PRE is a variable that gets defined and then assigned the first part (in my case 8 characters) of the element "name" of "this" which is the button. With other words it fetches the prefix of the name of the button as used on the form.

2. event_id is a variable (you could call it anything). This event_id gets assigned the id value by executing the method getElementById() with the obtained prefix (from the line before) and the Id of the record you are planing to display in the form to be opened. That id is the id of the record displayed in the row of the subform. (most nuBuilder coders seem to use the first three letters of the table together with the underscore and the letters id to refer to the primary index field of a table so mine should be event_id. But I just label my Ids always just with ids. Don't burn me for that.)

3. Then comes the fun part. You have to find the number of the form that you want to open. I have not found an easy way to find this number except to search through the source code of the page that opens when the target form is open. The quickest way is to search in the source code for the following:

Code: Select all

<i><span ondblclick="openForm('form', '14
The number starting with 14 should be the number you need to use.

So line 3 calls the openForm function and passes the two parameters a) the number of the form to be opened and b) the id of the current record.

Save the form reload and it should work.

Please any geniuses out there let me know if this is OK or if this can be improved.

I know the bad thing about this is that when you recreate the form your code needs to be fixed since the number is a string. There is also no way to know if the 8 characters are always 8 characters or if there will be a different length in other cases.
Fundi
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Open a form via a Button

Unread post by admin »

Fundi,

Here's a couple of nuBuilder/javascript functions that will make your job easier.

http://wiki.nubuilder.com/tiki-index.ph ... #nuGetRow_

nuGetRow()
Returns the subform row that has focus.

eg. If the row that has focus was row 2 in a subform named invoice_items, this function would return the string "invoice_items0001" (the first row being considered 0).


nuGetRowId()
Returns the Primary Key value for the Subform row with focus.


This...
dclick.PNG
dclick.PNG (29.75 KiB) Viewed 4972 times
Will give you this.. (yellow here is supposed to represent a double click)
dclickalert.PNG
dclickalert.PNG (53.72 KiB) Viewed 4972 times
And that...
drow.PNG
drow.PNG (4.61 KiB) Viewed 4972 times
Will give you that... (yellow here is supposed to represent a double click)
drowalert.PNG
drowalert.PNG (45 KiB) Viewed 4972 times
Hope it helps

Steven

.
Fundi
Posts: 27
Joined: Sun Apr 17, 2011 10:22 pm

Re: Open a form via a Button

Unread post by Fundi »

Thanks Steven

I have a confession to make. I had done pretty much every video tutorial (Excellent these I might say) except the Java script one. I thought java script (which I don't know very well) is just for manipulating stuff on forms and input fields like verifications etc. Well your references are hugely helpful and it will allow me to move to the next level.

Thanks for your trouble in making even screenshots.
Fundi
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Open a form via a Button

Unread post by admin »

Cheers

Steven
Post Reply