Element JS updates shown value, but it's not being saved

I have a js event on the checkbox, firing on "change" to update the value of a jdate field. It does a fine job of displaying the correct date on each state change. No console errors appear. However, even when displaying tne new date, after pressing the form's save button, the previous value of the jdate field flashes in the field and is saved. I'm not sure why or what to do about it.

Here's my JS:

JavaScript:
var checkbox = Fabrik.getBlock('form_2').elements.get('boats___confirm');
var checkboxValue = checkbox.getValue();
var confirmDateField = Fabrik.getBlock('form_2').elements.get('boats___last_confirmation_date');
var lastDateField = Fabrik.getBlock('form_2').elements.get('boats___previous_confirmation_date_calc');
var lastDateValue = new Date(lastDateField.get('value'));

if(checkboxValue == 1){
  var newDate = new Date();
  confirmDateField.set(newDate);
}
else{
  confirmDateField.set(lastDateValue);
}

thanks in advance!
 
Last edited:
Thanks LF. I didn't try matching the format to the one you suggested. But, I did play with formatting and substituting a simple string value to see if there was an issue like the one you've suggested. No joy. Still, I can type a yyyy-mm-dd into the field and it saves fine, so I think it should also work when I provide the same date as a string using the set or update method.

I was able to circumvent the problem by swapping the jdate field for a text field.

Could it be because the jdate element expects something like "2022-08-22 21:48:55", but "new Date()" in JS gives you "Mon Aug 22 2022 21:48:55 GMT+0800 (+08)"?
https://www.w3schools.com/js/js_dates.asp

Log your variable "newDate" to the console and see yourself.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top