Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Update field values to be saved in nuBeforeSave()? Topic is solved

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
incoherence
Posts: 22
Joined: Sun May 08, 2022 2:36 pm
Has thanked: 9 times
Been thanked: 1 time

Update field values to be saved in nuBeforeSave()?

Unread post by incoherence »

Hi, I have a field in a main form that records information about where the data originally came from.
If the user updates the data in the main form and hits "Save", I want to record that the data was also edited via my nuBuilder UI.
I tried to do this in Javascript by adding a nuBeforeSave() function.
The code I added gets the form data using $('#fieldname').val(), and then updates the form data using $('#fieldname').val(newvalue).
This appears to work (in the UI only), but the new value does not get updated in the database for the record being saved (it remains unchanged).

Questions:
* Can I only update the data being saved by using PHP BS (Before Save)? (Or in other words: am I too late to influence what gets saved once I am in nuBeforeSave() ?).
* In the diagram https://wiki.nubuilder.cloud/index.php? ... ntFlow.PNG where does JS nuBeforeSave() get called (for an Edit form in my case)? Can I consider that the "Save" box in the diagram (just up and to the right of "Edit Form") is not even entered if nuBeforeSave() returns false?
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Update field values to be saved in nuBeforeSave()?

Unread post by kev1n »

You need to trigger the change event since nuBuilder only saves records that have a class of "nuEdited"

Code: Select all

$('#fieldname').val(newvalue).change();
or use the inbuilt nuBuilder function:

Code: Select all

nuSetValue('fieldname', newvalue)
The JS BS gets called before PHP BS:
js_bs.png
If nuBeforeSave() is returns false, PHP BS is not called and hence the record not saved.
In the diagram, the blue save box indicates that the save button has been clicked.
You do not have the required permissions to view the files attached to this post.
incoherence
Posts: 22
Joined: Sun May 08, 2022 2:36 pm
Has thanked: 9 times
Been thanked: 1 time

Re: Update field values to be saved in nuBeforeSave()?

Unread post by incoherence »

Perfect - thanks kev1n!
Post Reply