Hi @acrspf,
I hope you are doing well today!
Yes, you can set an initial value in the mu-plugin code. You can try the following code to see if it helps;
<?php
add_action( 'wp_footer', function(){
?>
<script>
(function($){
$(function(){
let _form_id = 1211,
_date_field_id1 = 'date-1',
_date_field_id2 = 'date-2',
_days_field_id = 'number-1',//or enter text-field id
_separated_date = '/',
_form = $('#forminator-module-'+ _form_id);
if( _form.length ){
let _date_field1 = _form.find('[name="'+ _date_field_id1 +'"]' ),
_date_field2 = _form.find('[name="'+ _date_field_id2 +'"]' ),
_days_field = _form.find('[name="'+ _days_field_id +'"]');
// Here, set the initial value for days
_days_field.val("YOUR INITAL VALUE");
_date_field1.on('change', function(){
let _value = $(this).val();
if( _value ){
_date_field2_value = _date_field2.val();
if( _date_field2_value ){
calc_days( _value.split(_separated_date), _date_field2_value.split(_separated_date), $(this).data('format').split( _separated_date ) );
}
}
});
_date_field2.on('change', function(){
let _value = $(this).val();
if( _value ){
_date_field1_value = _date_field1.val();
if( _date_field1_value ){
calc_days( _date_field1_value.split(_separated_date), _value.split(_separated_date), $(this).data('format').split( _separated_date ) );
}
}
});
function calc_days( _date_value_1, _date_value_2, _date_format ){
let _date1 = {}, _date2 = {};
for( let _t in _date_format ){
_date1[ _date_format[_t] ] = _date_value_1[ _t ];
_date2[ _date_format[_t] ] = _date_value_2[ _t ];
}
// Fill age field.
_date1 = new Date(_date1['yy'], _date1['mm'], _date1['dd'] );
_date2 = new Date(_date2['yy'], _date2['mm'], _date2['dd'] );
_form.find('[name="'+ _days_field_id +'"]').val( Math.round( Math.abs( _date2 - _date1 ) / 86400000 ) );
}
}
});
})(window.jQuery);
</script>
<?php
}, 21 );
Please replace “YOUR INITAL VALUE” with the initial value you would like. Also make sure to update form ID to suit yours. This will set the initial value for the days field before any date picker fields are used. Remember that this is a string value, if you want it to be a number you can remove the quotes.
Kind regards,
Zafer
Hello @acrspf ,
It looks like my colleague’s code helped solve your issue as we haven’t heard back from you for some time now.
I will resolve this topic, but if you have more questions feel free to re-open it.
kind regards,
Kasia