skyrun
Active Member
i would like to change element B (completeddate) based on the value of element A (status) if B is blank. so i have put the following javascript on element A (status) that fires when the status is changed:
so this code is on the status element set to fire when status is changed (which works).
the js code above correctly puts today's date into 'completeddate' (which is a date type element) when i change status to 3, 4 or 6 AND the date is blank. then i can save the form and it all works. that's the 'normal' use-case.
you'll see that i am attempting to edit the fabrik field using the DOM and using jQuery. i wouldn't need to do both of course, just trying mutiple ways of doing the same thing because of the issue below. this could be related... also note that if i check and update srms_work_orders___completeddate (vs not srms_work_orders___completeddate_cal, adding a _cal, which i can see in the dom is added to that field, probably because it's a calendar?) then it us 'undefined'. i have to put the _cal on there to get data.
my issue is the following use case that i can't get to work.
1) i type in a datecompleted of 6/11/19 (for example) on the form and save it.
2) i open the form to the same record and blank out the datecompleted manually.
3) then i change status to one of the status' so that datecompleted fills in as today's date (6/19/19 in this case) by the javascript above.
so far so good. the screen looks right and 06/19/19 is in the datecompleted field... however...
4) when i press 'save' or 'apply' on the form, the date changes back immediately to the LAST SAVED value '06/11/19' on the screen and it also saves 06/11/19 (not the value that was there when i pressed save) in the table. ignoring the value displayed on the form. if i change the date by typing in 06/19/19 or selecting that on the calendar, then it works. but the .js is not changing something deeper than what's displayed on the form...
JavaScript:
/* Set Date Completed if status changed to 3, 4 or 6 AND date completed not set */
requirejs(['fab/fabrik'], function () {
/*console.log('status: CHANGE fired');*/
var wostatus = document.getElementById('srms_work_orders___status');
var completeddate = document.getElementById('srms_work_orders___completeddate_cal');
/*console.log('status=' + wostatus.value);
console.log('completeddate=' + completeddate.value);*/
if ((wostatus.value == 3 || wostatus.value == 4 || wostatus.value == 6) && (completeddate.value === '' || typeof completeddate.value === 'undefined')) {
/*console.log('set to todays date');*/
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); /*January is 0*/
var yy = today.getFullYear().toString().substr(-2);
completeddate.value = mm + "/" + dd + "/" + yy;
/* TRY ANOTHER WAY, STILL NOT WORKING*/
var $completeddate = $('srms_work_orders___completeddate');
/* Copy value */
$completeddate.value = mm + "/" + dd + "/" + yy;
console.log('setting jquery completed date');
/* Since we changed the value, trigger any change events on the price_used field */
$completeddate.fireEvent('change');
}
});
so this code is on the status element set to fire when status is changed (which works).
the js code above correctly puts today's date into 'completeddate' (which is a date type element) when i change status to 3, 4 or 6 AND the date is blank. then i can save the form and it all works. that's the 'normal' use-case.
you'll see that i am attempting to edit the fabrik field using the DOM and using jQuery. i wouldn't need to do both of course, just trying mutiple ways of doing the same thing because of the issue below. this could be related... also note that if i check and update srms_work_orders___completeddate (vs not srms_work_orders___completeddate_cal, adding a _cal, which i can see in the dom is added to that field, probably because it's a calendar?) then it us 'undefined'. i have to put the _cal on there to get data.
my issue is the following use case that i can't get to work.
1) i type in a datecompleted of 6/11/19 (for example) on the form and save it.
2) i open the form to the same record and blank out the datecompleted manually.
3) then i change status to one of the status' so that datecompleted fills in as today's date (6/19/19 in this case) by the javascript above.
so far so good. the screen looks right and 06/19/19 is in the datecompleted field... however...
4) when i press 'save' or 'apply' on the form, the date changes back immediately to the LAST SAVED value '06/11/19' on the screen and it also saves 06/11/19 (not the value that was there when i pressed save) in the table. ignoring the value displayed on the form. if i change the date by typing in 06/19/19 or selecting that on the calendar, then it works. but the .js is not changing something deeper than what's displayed on the form...
Last edited: