Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    CSS in general should handle that with something like https://stackoverflow.com/a/19644231 or custom classes added via the attributes parameter for your field could help as well.

    There won’t be one “right” way to handle this one.

    Thread Starter dkurth

    (@dkurth)

    I ended up doing a custom field and there I added the css code accordingly. The link, suggested above, changes all the input fields through-out the site, not just the local field.

    function cmb2_render_callback_required_text($field, $escaped_value, $object_id, $object_type, $field_type_object)
    {
    ?>	
    
    <input type="text" id="<?php echo $object_type; ?>" style="border-color:#FC6; border-width:thick;" value="<?php echo $escaped_value; ?>">
    
    <?php
    }
    add_action( 'cmb2_render_required_text', 'cmb2_render_callback_required_text', 10, 5 );
    
    function sm_cmb2_sanitize_required_text( $null, $new ) {
    
    return $new;
    }
    add_filter( 'cmb2_sanitize_required_text', 'sm_cmb2_sanitize_required_text', 10, 2 );
    
    ///////////////////
    //
    //////////////////////
    function cmb2_render_callback_readonly_text($field, $escaped_value, $object_id, $object_type, $field_type_object)
    {
    ?>	
    
    <input type="text" id="<?php echo $object_type; ?>" style="background-color: transparent; border: 0px solid;" value="<?php echo $escaped_value; ?>">
    
    <?php
    }
    add_action( 'cmb2_render_readonly_text', 'cmb2_render_callback_readonly_text', 10, 5 );
    
    function sm_cmb2_sanitize_readonly_text( $null, $new ) {
    
    return $new;
    }
    add_filter( 'cmb2_sanitize_readonly_text', 'sm_cmb2_sanitize_readonlytext', 10, 2 );
    
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Yes, it would need to be tailored to your specific fields via CSS selectors, so that it wouldn’t be absolutely every readonly input in the page. It was more to give you an idea of how to go about this, since there’s no built-in way with CMB2.

    Thread Starter dkurth

    (@dkurth)

    I figured it out using the attributes override.

    Specifically the class definition. the only thing that does not seem to work with using your own class definition, is changing the borders. They stay there, whether you want them or not. Even if you define the border width to be 0.

    'attributes'  => array(  'class' => 'CMB2RequiredField' ),	
    
    • This reply was modified 5 years, 9 months ago by dkurth.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    At that point, I’d start digging into the specificity and the strength of your custom CSS. Even getting “dirty” and adding !important to yours should net you something for new results. Sometimes you may need more than just .CMB2RequiredField { border: 0; }

    Thread Starter dkurth

    (@dkurth)

    Good point. had not thought of that.

    Thread Starter dkurth

    (@dkurth)

    and that fixed it. Thank you.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘READY ONLY FIELD FORMAT’ is closed to new replies.