Welcome to the nuBuilder Forums!

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

Calculated Fields are not saved to database

Questions related to using nuBuilder Forte.
Post Reply
hagie
Posts: 20
Joined: Fri Dec 16, 2016 12:51 pm

Calculated Fields are not saved to database

Unread post by hagie »

Hi,

I created a form with several fields which are calculated by a php / js callback script. In the onChange event I call:

Code: Select all

nuSetProperty('source_field', 'address');nuRunPHPHidden("updateFields");
and the "updateField" prcedure uses the source field to get some value from the internet, formating them and send them back via a js callback script :

Code: Select all

...
php magic to get data
$addr = $result->data[0]->address;

$js = "
$('#address').val('$addr');
";
nuJavascriptCallback($js);
Everything works fine , I get the informations in the fields back in the frontend, but if I save them now Only those fields which were direct manipulated by myself are saved to the database. All pure computed fields are not save to the database.

Do I need to set some "was edited flag" to the fields I calculated ?

Thanks
Stefan
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Calculated Fields are not saved to database

Unread post by kev1n »

After setting a value by script you need to invoke the change() event. This will add the class nuEdited to the object. Only fields that have this class will be saved to the database.

Code: Select all

$('#address').val('$addr').change();
hagie
Posts: 20
Joined: Fri Dec 16, 2016 12:51 pm

Re: Calculated Fields are not saved to database

Unread post by hagie »

kev1n wrote:After setting a value by script you need to invoke the change() event. This will add the class nuEdited to the object. Only fields that have this class will be saved to the database.

Code: Select all

$('#address').val('$addr').change();
Thank you works like a charm, now I have a different problem.

There are two fields which update each other. Both use the same Script which results in a loop. Is there another way to get a field saved without calling the .change() event.

Think of it like a Name / Account relation - If you enter the account it fills in the Name, if you enter the Name it fills in the Account - both by using the onChange Event and calling the script.

One "dirty" workaround is to compare the values in the update Script, if they are same don't run or don't call the change() again. But still ugly because the script runs at least two times.

Stefan
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Calculated Fields are not saved to database

Unread post by kev1n »

Adding the nuEdited class to the fields should do the trick.

Code: Select all

$('#address').val('$addr').addClass('nuEdited');
hagie
Posts: 20
Joined: Fri Dec 16, 2016 12:51 pm

Re: Calculated Fields are not saved to database

Unread post by hagie »

kev1n wrote:Adding the nuEdited class to the fields should do the trick.

Code: Select all

$('#address').val('$addr').addClass('nuEdited');
Thank you again - works !

Stefan
hagie
Posts: 20
Joined: Fri Dec 16, 2016 12:51 pm

Re: Calculated Fields are not saved to database

Unread post by hagie »

Hi ,

how can I set a checkbox filed from the js callback script. Setting to 1 or "1" or php true don't work.

Is there a discord / Telegram / Slack for nuBuilder - it would be great to get some real time communication / collaboration .

Thanks
Stefan
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Calculated Fields are not saved to database

Unread post by kev1n »

Code: Select all

$("yourcheckboxId").prop('checked', true).change();
Is there a discord / Telegram / Slack for nuBuilder - it would be great to get some real time communication / collaboration .
But what not is, can still be one day...
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Calculated Fields are not saved to database

Unread post by kev1n »

I created a discord nuBuilder server. Feel free to join: https://discord.gg/UcbJYw2
Post Reply