Hello,
I created a field “u_region” in a group visible on the user pages (new, edit and profile).
In the “functions.php” I wrote:
function acf_admin_enqueue( $hook ) {
global $pagenow;
if ( in_array( $pagenow, array(‘user-new.php’,’user-edit.php’,'profile.php') ) ) { // Only on user pages
wp_enqueue_script( ‘populate-area’, get_stylesheet_directory_uri() . ‘/js/autopopulatesusers.js’, array( ‘jquery’, ‘underscore’, ‘acf-input’) );
wp_localize_script( ‘populate-area’, ‘pa_vars’, array(
‘pa_nonce’ => wp_create_nonce( ‘pa_nonce’ ), // Create nonce which we later will use to verify AJAX request
));
}
}
And the “autopopulatesusers.js” file contains:
jQuery(document).ready(function($) {
var selected_reg = $( ‘#acf-field-u_region’ ).val();
console.log(‘selected_reg = [‘ + selected_reg + ‘]’);
});
But in the console, the log is:
selected_reg = [undefined]
I have to say the exact same code with “p_region” fields works perfectly on the posts and return a defined log (“selected_reg = [ALSACE]”).
Is it a a way to fix this issue ?
Cheers