Page 1 of 1

Calculated Fields are not saved to database

Posted: Thu May 14, 2020 10:32 am
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

Re: Calculated Fields are not saved to database

Posted: Thu May 14, 2020 10:49 am
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();

Re: Calculated Fields are not saved to database

Posted: Thu May 14, 2020 12:16 pm
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

Re: Calculated Fields are not saved to database

Posted: Thu May 14, 2020 12:19 pm
by kev1n
Adding the nuEdited class to the fields should do the trick.

Code: Select all

$('#address').val('$addr').addClass('nuEdited');

Re: Calculated Fields are not saved to database

Posted: Thu May 14, 2020 1:18 pm
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

Re: Calculated Fields are not saved to database

Posted: Thu May 14, 2020 1:33 pm
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

Re: Calculated Fields are not saved to database

Posted: Thu May 14, 2020 1:49 pm
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...

Re: Calculated Fields are not saved to database

Posted: Thu May 14, 2020 1:57 pm
by kev1n
I created a discord nuBuilder server. Feel free to join: https://discord.gg/UcbJYw2