Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Anh Tran

    (@rilwis)

    If you don’t need the input box, you can use the custom_html type, like this:

    array(
        'id' => 'field_id',
        'type' => 'custom_html',
        'name' => 'Field Name',
        'std' => 'Value', // This value is displayed as a HTML text, so users can't change it
    )

    If you need the input box, you can use the filter rwmb_{$field_id}_html, like this:

    add_filter( 'rwmb_YOUR_FIELD_ID_html', 'prefix_input_readonly' );
    function prefix_input_readonly( $html )
    {
        return str_replace( '<input', '<input readonly', $html );
    }
    Thread Starter gonzalezea

    (@gonzalezea)

    Although I don’t need input box, I prefer second way because MB already bring me the value (lazy programmer here !!). I just did some modification.

    Thanks !!

    return str_replace(
            array(
                '<input',
                '<textarea',
                '<select',
            ),
            array(
                '<input readonly',
                '<textarea readonly',
                '<select disabled',
            ),
            $html );
    Plugin Author Anh Tran

    (@rilwis)

    FYI, I’ve just added this to documentation, so other people can search faster:

    https://metabox.io/docs/how-to-set-a-field-as-read-only/

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to set a field as read only?’ is closed to new replies.