Support

Account

Home Forums Feature Requests Read-Only Field Reply To: Read-Only Field

  • I’ve tried that plugin and it doesn’t seem to run/display AFC’s the_field.

    I’ve been playing with trying to use jQuery to disable input, I have it working for the date picker, but no luck on select2.

    <?php // Disable AFC fields based on user role/
    
    if( !current_user_can( 'administrator' ) ):
    function disable_acf_load_field( $field ) {
    
          $field['disabled'] = true;
    
    return $field;
    
    }
    add_filter('acf/load_field/name=project_code', 'disable_acf_load_field');
    add_filter('acf/load_field/name=project_type', 'disable_acf_load_field');
    add_filter('acf/load_field/name=project_status', 'disable_acf_load_field');
    add_filter('acf/load_field/name=funding_year', 'disable_acf_load_field');
    add_filter('acf/load_field/name=start_date', 'disable_acf_load_field');
    add_filter('acf/load_field/name=end_date', 'disable_acf_load_field');
    add_filter('acf/load_field/name=state', 'disable_acf_load_field');
    add_filter('acf/load_field/name=project_primary_institution', 'disable_acf_load_field');
    add_filter('acf/load_field/name=pi_contact', 'disable_acf_load_field');
    
    //Backend jquery
    add_action('admin_print_footer_scripts', 'afc_disable_admin_jquery');
    function afc_disable_admin_jquery(){
    ?>
    
    <script>
    jQuery(function(jQuery) {
      jQuery(document).ready(function(){
    
        jQuery(".hasDatepicker").prop('disabled', 'disabled');
    
      });
    });
    </script>
    <?php
    }
    
    endif;