Detail view field calculation update issue

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
bwalker
Posts: 13
Joined: 2021-05-24 22:30

Detail view field calculation update issue

Post by bwalker » 2021-06-14 19:45

Hello group, me again,
I have this js code from the udemy course that updates the age field of the employee table.
The code works if I do a save but will not update the 'age' field after selecting a new BirthDate .
I believe it is supposed to update the form on a new selection then the DB on the save.
here is the code in the 'employee-dv.js' file
$j(function(){
$j('#Age').prop('readonly',true);

$j('#BirthDate-dd,#BirthDate-mm,#BirthDate').change(function(){
var dob = get_date('BirthDate');
var today = new Date();
var age = Math.floor((today-dob) / 1000/60/60/24/365.25);

$j('#Age').val(age);
});
$j('#BirthDate').change();
});
Thanks for any direction you can offer,
Bill Walker

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Detail view field calculation update issue

Post by pbottcher » 2021-06-14 21:47

Hi,

I think you are missing the get_date function (at least in your post)
Also please use the code formating feature to put your code in the post. This makes reading easier.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

bwalker
Posts: 13
Joined: 2021-05-24 22:30

Re: Detail view field calculation update issue

Post by bwalker » 2021-06-14 23:27

The get_date function is in the footer-extras.php file as it is used in multiple places.
Here is it's code:
<script>
function get_date(date_field){
var y = $j('#'+ date_field).val();
var m = $j('#'+ date_field + '-mm').val();
var d = $j('#'+ date_field + '-dd').val();

var date_object = new Date(y, m - 1, d);

if(!y) return false;

return date_object;
}
</script>
I will have to investigate the code formatting feature.
Thank you.

bwalker
Posts: 13
Joined: 2021-05-24 22:30

Re: Detail view field calculation update issue

Post by bwalker » 2021-06-15 13:13

OK, so this is getting strange. None of this code is even being called. I have commented out the whole function and yet the AGE is still getting calculated on SAVE only. So where is this coming from? That is what I need to figure out.
I will report back any results found.
Thanks

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Detail view field calculation update issue

Post by pfrumkin » 2021-06-15 20:16

Hi

Does the line
var dob = get_date('BirthDate');
need to be
var dob = get_date('#BirthDate');

~Paul

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Detail view field calculation update issue

Post by pbottcher » 2021-06-16 19:12

The code is fine. The error must be somewhere else. Check for other error like upper/Lowecase mismatch, Errors in the console.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

Post Reply