Page 1 of 1

Update field values to be saved in nuBeforeSave()?

Posted: Tue Mar 07, 2023 1:27 am
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?

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

Posted: Tue Mar 07, 2023 5:56 am
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.

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

Posted: Tue Mar 07, 2023 2:17 pm
by incoherence
Perfect - thanks kev1n!