Page 1 of 1

How to put a button on a form to do something.

Posted: Wed Feb 10, 2021 11:23 pm
by icoso
I have tried... I have read the OLD and NEW user guides. I have searched the forums (add button, add a button, nfunctions, functions, call a form, etc.) and read numerous posts. I have read the wikis. I still cant find how to add a button on a form to open another form. It's just not intuitive. I've found a lot of simple things (that I think should be simple are not simple, nor intuitive with this DB system and I've ONLY been at this for 3 days. I just found this system 3 days ago. I've written numerous database systems, applications, web apps, web sites, etc. and honestly not sure why simple things that can normally be easily accomplished and logical are not with this DB system. Like adding Masks to field formats, or using "lookup tables" (called selects here) for field validation, etc.. (Maybe its just me...) But I digress... After spending hours trying to figure out something and how it works I can accomplish quite a lot and even after just 3 days can see the potential for a DB system like nuBuilder for some of my clients. Its just getting there has so far been excrutiatingly slow for the simplest of tasks.

How do I add a button on an existing form to open another existing form for editing the current record that Im looking in view mode?

I created a Browse and Edit form using the Fast Forms designer. It created the table, and I modified it and adjusted it to my liking. I then did some reading... and more reading... and more... because my though on this was, I do not want some users to be able to EDIT the fields on this table once they have been saved int he database. So I found out how to duplicate (clone) a form by searching and reading the forums and piecing together an answer. I created a "Browse" clone of my edit form. Except it still allowed me to edit the fields. So then I changed the form so that ALL the fields were ReadOnly and now I want to add a BUTTON on that form so that if the user clicks it, the form opens into edit mode and all the fields magically open for editing. I figured the easiest way to do this would be to open the current record into another Form (or the original form that I cloned) that allowed the user to edit the record info. After spending a couple of hours searching and reading I came across a post that kind of discussed adding a Next button to a form and how to do that. It said to add the following (I've changed it slightly to fit my needs) to the Javascript of the form.

Code: Select all

 nuAddActionButton('EditTaxForm', 'Edit TaxForm', 'nuForm('FF1', '', '', '', '2')');
However according to the wiki the 2nd param of the nuform function should have the "record id of the Edit Form or an empty string to display a Browse Form." I can't find this record id in any of the screens for the FF1 form. Where do I find this record ID? Regardless, adding this Javascript DOES NOT add an Action Button to the form screen. It doesn't do anything but sit and laugh at me to try, try again.... (again excruciatingly slow...) for something that I could so easily in Access or using PHP on my self made forms, or in VB, or in C++, or just about anything else...

These are simple things that takes HOURS to figure out and I'm not sure why... If ANYONE can point me in the right direction on How to Add a Button to a form that does something... like open another form to edit the information that is on the current form, that would be FANTASTIC! I haven't even gotten to the part where I want to perform a "lookup" (I guess thats what its called here) to another relational table (one to many) to show all the records for the main Customer from the ExistingOrders table that then I can click on that record ID and open a Browse Only frm of that record.) That's next. Additionally, I need to be able to while "Viewing" a record, be able to click a button that would "Duplicate the record into a new form (except a few of the fields or change a few like a orderdate field.)

I have so much to learn... Thank you for your guidance...

Re: How to put a button on a form to do something.

Posted: Thu Feb 11, 2021 3:42 am
by kev1n
Hi,

The syntax is invalid:

Code: Select all

nuAddActionButton('EditTaxForm', 'Edit TaxForm', 'nuForm('FF1', '', '', '', '2')');
Use the Developer Console (F12) to check and run code.
Or use a JS validator to check the syntax: https://esprima.org/demo/validate.html
console.png

Code: Select all

nuAddActionButton('EditTaxForm', 'Edit TaxForm', 'nuForm("FF1", nuCurrentProperties().record_id, "", "", "2")');
Also replace FF1 with the form Id (= Primary Key)

Re: How to put a button on a form to do something.

Posted: Thu Feb 11, 2021 4:36 pm
by icoso
Was the wiki changed? Because I copied the format of that nuAddActionButton directly from the Wiki and what it shows NOW is NOT what it showed yesterday when I spent hours trying to figure out how to add a button to a form. Of course the bottom of the wiki shows: This page was last modified on 9 February 2021, at 00:00. I even cut and PASTED exactly from the wiki page in my post: "record id of the Edit Form or an empty string to display a Browse Form" and that's not there either... Either that or I was looking at an OLD wiki page hidden somewhere in the depths of the wiki... But I digress...

In my code I have two open "(" and two close ")". I have each of the variables surrounded by ' just like the OLD original wiki page showed. The only thing I didn't have was the "record id of the Edit Form " which I asked about. Oh but I see that should use nuCurrentProperties().record_id to get the record ID of the form.

I just searched for "how to get record id" in the forums and there were: "No suitable matches were found."
I found the term "Record ID" in the wiki at: https://wiki.nubuilder.cloud/ ... rm_Builder but it doesn't discuss nuCurrentProperties() so I looked that up . I found its a JAVASCRIPT function.... that returns all properties for the current Form as an object... GREAT! for JAvascript. (I wonder if there is a similar thing for PHP???) Now to find all these properties. Any EASY way to print them off or to SEE them?

I believe FF1 is my form ID. Thats whats listed in my forms list screen (nuBuilder Form) for that form that I want to call up using the button, under the Code column. Wouldn't that be the form ID? Or would I check my OBJECTS and find it as one of my RUN objects, and use that ID for that form? ie: "ff6021e47fd6d285b" ????

I tried both. I now have a button at the top for "Edit Tax Form" but when I click it, It opens a new window and i just get a blank screen. I kind of assumed that it would open that form that has all the fields on it in edit mode. I also get that same button on the Search screen, which makes NO sense. because I haven't selected an item to view yet. I ONLY should see this on that form screen that I view the record on, then when I click it, it should open the form that I can EDIT the fields.

Im losing hope....

Re: How to put a button on a form to do something.

Posted: Thu Feb 11, 2021 4:46 pm
by kev1n
The wiki has a change history. So you can easily verify by comparing different versions that nothing has changed there...
You can also check the snapshots of web.archive.org: https://web.archive.org/web/20201128104 ... Javascript

For PHP, use nuHash(). Output it to nuDebug Results with

Code: Select all

nuDebug(nuHash());
There are various ways to find a form's ID:

Open the form in nuBuilder, then
1. Options Menu > Form Info
2. Press CTRL+SHIFT+I
3. Developer Console: Enter nuCurrentProperties().form_id

Or
4. Look in the Database table zzzzsys_form, column zzzzsys_form_id

Re: How to put a button on a form to do something.

Posted: Thu Feb 11, 2021 6:23 pm
by icoso
I used FF1 and the ff6021e47fd6d285b which I think is the ID. But - I checked the form info and found

Form ID: 6021e47fd6d285b
Form Code: FF1

So I used: 6021e47fd6d285b and it opens this form in edit mode in a new window. Can I open it in the current window? how?


2. Why is the Edit Tax Form Button on the Search screen?
This makes no sense, because I haven't selected an item to view yet. I want it on the form itself. I ONLY should see this button on that form screen that I view/edit the record on, then when I click it, it should open the Edit Form that I can EDIT the fields.

How can I remove this button from the Search screen and only have it show up on the View form?

Re: How to put a button on a form to do something.

Posted: Thu Feb 11, 2021 6:30 pm
by kev1n
icoso wrote:Can I open it in the current window? how?
Ths JS functions are documented in the wiki:
https://wiki.nubuilder.cloud/ ... ipt#nuForm
How can I remove this button from the Search screen and only have it show up on the View form?
The Custom Code is executed whenever a Browse or Edit Form is loaded.

To run certain code only when in Edit Mode, check the form type with nuFormType() as shown in the example here:

https://wiki.nubuilder.cloud/ ... Javascript
formtype.png