Hi everyone,
I hope that you all are safe and healthy during this challenging time.
I have created an application for plant growers for them to monitor their plant growth etc.
User will select the plant and the estimated harvesting duration will automatically be populated in the harvest duration field.
My goal is whenever user change or select the "Plant", the "Estimated harvest date" will be automatically populated based on the changes of the "Harvest duration" value (days).
You can check the application at
https://mythinkpositive.com/samples/hydroponic
with Username and Password : demo
Your kind attention and help is highly appreciated.
Thank you and have a nice day.
Zala.
Auto change or populate date based on duration value
Auto change or populate date based on duration value
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Re: Auto change or populate date based on duration value
Hi Zala,
hope you and your loved ones are well too.
I suppose you have implemented some JS already to automatically update the Harvest Duration on change of the Plant type (or jsetzes AGHelper).
So, since fiddling with JS (which is not my area usually, but I want to make a suggestion anyways), why not grab the value from the start date field (start_date?) and simply add the Harvest Duration to that?
Probably some workflow like this
On change of Harvest Duration (which equals change of product in your application)
a) Get new value from harvest duration something like
b) write this to variable maybe harvestduration
c) get day from start date
d) get month from start date
e) get year from start date
f) build date from these three
g) use moments.js which is already loaded to calculate new date
h) split values
i) write new est harvest date day, month, year
Again: JS is not my primary (nor secondary) world, so maybe someone with more knowledge in this area is able to do a JS-oneliner.
Maybe see the AppGini Helper from jsetzer, who also has a page how to react on lookup changes (which I did not find right now).
Olaf
hope you and your loved ones are well too.
I suppose you have implemented some JS already to automatically update the Harvest Duration on change of the Plant type (or jsetzes AGHelper).
So, since fiddling with JS (which is not my area usually, but I want to make a suggestion anyways), why not grab the value from the start date field (start_date?) and simply add the Harvest Duration to that?
Probably some workflow like this
On change of Harvest Duration (which equals change of product in your application)
a) Get new value from harvest duration something like
Code: Select all
document.querySelector("#harvest_duration").value
c) get day from start date
Code: Select all
document.querySelector("#start_date-dd").value
Code: Select all
document.querySelector("#start_date-mm").value
Code: Select all
document.querySelector("#start_date").value
g) use moments.js which is already loaded to calculate new date
h) split values
i) write new est harvest date day, month, year
Again: JS is not my primary (nor secondary) world, so maybe someone with more knowledge in this area is able to do a JS-oneliner.
Maybe see the AppGini Helper from jsetzer, who also has a page how to react on lookup changes (which I did not find right now).
Olaf
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
Re: Auto change or populate date based on duration value
Hi,
you can try to add to your Pots-dv.js
and change the
/* on changing plant, retrieve harvest duration from plants table and populate harvest duration field */
you can try to add to your Pots-dv.js
Code: Select all
function put_date(date_field, dt){
$j('#' + date_field).val(moment(dt).format("Y"));
$j('#' + date_field + '-mm').val(moment(dt).format("M"));
$j('#' + date_field + '-dd').val(moment(dt).format("D"));
return ;
}
and change the
/* on changing plant, retrieve harvest duration from plants table and populate harvest duration field */
Code: Select all
$j('#plant-container').on('change', function(){
if(pid == '{empty_value}'){
$j('#harvest_duration').val('');
}else{
$j.ajax({
url: 'test.php',
data: { pid: 3 },
success: function(data){
$j('#harvest_duration').val(data);
var dt=get_date('start_date');
var nw =moment(dt).add(data,'d');
put_date('est_harvest_date', nw);
}
});
}
});
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.
Re: Auto change or populate date based on duration value
Hi pböttcher,
Thank you so much for the help. You are brilliant!!! I have changed a bit to become like the following and it is working perfectly.
I am not good at coding and I hope you don't mind helping me a bit more.
I am also trying to automatically change the est_harvest_date whenever user change the start_date or the harvest_duration as well.
Your kind attention and help is highly appreciated.
Thanking you in advance.
Zala.
Thank you so much for the help. You are brilliant!!! I have changed a bit to become like the following and it is working perfectly.
Code: Select all
$j('#plant-container').on('change', function(){
var pid = $j('#plant-container').select2('val');
if(pid == '{empty_value}'){
$j('#harvest_duration').val('');
}else{
$j.ajax({
url: 'hooks/ajax-harvest-duration.php',
data: { pid: pid },
success: function(data){
$j('#harvest_duration').val(data);
var dt=get_date('start_date');
var nw =moment(dt).add(data,'d');
put_date('est_harvest_date', nw);
}
});
}
});
I am also trying to automatically change the est_harvest_date whenever user change the start_date or the harvest_duration as well.
Your kind attention and help is highly appreciated.
Thanking you in advance.
Zala.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Re: Auto change or populate date based on duration value
Hi Zala,
well spotted, Sorry I left my test in there while pasting the code.
You may try
well spotted, Sorry I left my test in there while pasting the code.
You may try
Code: Select all
$j('#harvest_duration, [id^="start_date"]').on('change', function(e){
var data = parseInt($j('#harvest_duration').val()) || 0;
var dt=get_date('start_date');
var nw =moment(dt).add(data,'d');
put_date('est_harvest_date', nw);
});
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.
Re: Auto change or populate date based on duration value
Thank you so much pböttcher. It is working as intended. You made my day wonderful during this hard time.
Also not forgetting Olaf for showing the path.
Thanks guys.
Also not forgetting Olaf for showing the path.
Thanks guys.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Re: Auto change or populate date based on duration value
Hi Pböttcher,
I hope you well and safe always.
Need help from you related to this issue.
The solution you provided works as expected for the 'start_date' field as data type "Date".
It didn't work if I change the 'start_date' field's data type to "Datetime".
I am assuming that it has something to do with the get_date function.
Appreciate if you can help me with the solution.
Thanking you in advance.
Zala.
I hope you well and safe always.
Need help from you related to this issue.
The solution you provided works as expected for the 'start_date' field as data type "Date".
It didn't work if I change the 'start_date' field's data type to "Datetime".
I am assuming that it has something to do with the get_date function.
Appreciate if you can help me with the solution.
Thanking you in advance.
Zala.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Re: Auto change or populate date based on duration value
Hi,
why did you change the field type? Is there a reason when we are talking about harvest dates?
If nothing else helps (pbötcher is our man here ) you could cut the time off the field contents and then do the calculation - and add the time back to it afterwards.
Olaf
why did you change the field type? Is there a reason when we are talking about harvest dates?
If nothing else helps (pbötcher is our man here ) you could cut the time off the field contents and then do the calculation - and add the time back to it afterwards.
Olaf
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
Re: Auto change or populate date based on duration value
Hi,
yes of course. If you change the fieldtype, the script need to be adjusted as well.
you can try ( assuming the your datetime field display as dd-mm-yyyy hh:mm:ss )
yes of course. If you change the fieldtype, the script need to be adjusted as well.
you can try ( assuming the your datetime field display as dd-mm-yyyy hh:mm:ss )
Code: Select all
function get_date(date_field){
var arr = $j('#' + date_field).val().split(/ |-/);
var y = arr[2];
var m = arr[1];
var d = arr[0];
var date_object = new Date(y, m - 1, d);
if(!y) return false;
return date_object;
}
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.
Re: Auto change or populate date based on duration value
Hi Pböttcher,
You never fail me... Thank you so much!!!
and Olaf, the reason is I need to specify the harvesting time as well due to some time sensitive plants and logistic issue. Hope this explained.
Thanks my friends.
Zala.
You never fail me... Thank you so much!!!
and Olaf, the reason is I need to specify the harvesting time as well due to some time sensitive plants and logistic issue. Hope this explained.
Thanks my friends.
Zala.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.