Support

Account

Home Forums Feature Requests Read-Only Field

Solving

Read-Only Field

  • sorry – I forgot to mention that this is a JS code. this code will only be loaded on the CPT with this fields.

  • I had the same problem with a disabled post_object field: its value is lost on save.

    Ended with this workaround:

    
    add_filter('acf/update_value/name=companies', function ($value, $user_id, $field, $original) {
        //debug
        //error_log('Saving companies: ' . json_encode($value) . ' ' . $user_id);
        //error_log('Last value: ' . get_field('companies', $user_id));
    
        /*
         * Workaround for read only field where its value is reset
         * on the edit profile screen to ''.
         *
         * We set its value always to an array [] (empty or with companies).
         */
        if ($value === '') {
            $value = get_field('companies', $user_id);
        }
    
        return $value;
    }, 10, 4);
    

    Quite a hack but it works now fine.

Viewing 2 posts - 51 through 52 (of 52 total)

The topic ‘Read-Only Field’ is closed to new replies.