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?
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.
Update field values to be saved in nuBeforeSave()? Topic is solved
-
- Posts: 22
- Joined: Sun May 08, 2022 2:36 pm
- Has thanked: 9 times
- Been thanked: 1 time
-
- nuBuilder Team
- Posts: 4294
- 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()?
You need to trigger the change event since nuBuilder only saves records that have a class of "nuEdited"
or use the inbuilt nuBuilder function:
The JS BS gets called before PHP BS:
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.
Code: Select all
$('#fieldname').val(newvalue).change();
Code: Select all
nuSetValue('fieldname', newvalue)
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.
-
- Posts: 22
- Joined: Sun May 08, 2022 2:36 pm
- Has thanked: 9 times
- Been thanked: 1 time