Support

Account

Home Forums Backend Issues (wp-admin) Change another field when Time picker field is changed Reply To: Change another field when Time picker field is changed

  • There isn’t any documentation on how to update ACF fields in this manner. I have done some work with getting and setting values of ACF fields in JavaScript, but I have not worked with the date/time fields. With the date/time fields it’s not just a matter of setting a value, but also triggering the jQuery date picker to update correctly, or in some other way to make the change. I can tell you that the field that your targeting is only the displayed field. There is a hidden field that actually holds the value.

    There may also be a problem with detecting that the first field is changed. Hidden fields to not trigger all of the same actions that other types of fields trigger. So your first step needs to be figuring out if your action firing at all. You can do this by logging something to the console to see if the action is getting triggered.

    
    // JavaScript Document
    (function($) {
    	$(document).ready(function(){
    		if (typeof acf == 'undefined') { return; }
    			$('#acf-field_5883db4f3d228').on('input', function() {
    				// do something
    				console.log('do something');
    				$('[data-name="report_time_end"] input.hasDatepicker').val( 'test' );
    			});
    	});
    })(jQuery);