• Before diving into the plugin I’d like to know something that CMB2 doesn’t do.

    I’d like to setup text fields and make the information required entry. Like for a person directory, ensure that on save we have a phone number and if it’s not entered throw back a notice somewhere.

    Is that possible?

Viewing 1 replies (of 1 total)
  • Plugin Author htmlBurger

    (@htmlburger)

    You can do that with Carbon Fields:

    Field::make('text', '_crb_phone_number')->set_required(true)

    You can also that with CMB2 via “required” attribute:
    https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Field-Types#attributes

    
    array(
        'name'        => 'Extra Small Textarea',
        'id'          => $prefix .'xtra_small_textarea',
        'type'        => 'textarea_small',
        'attributes'  => array(
            'placeholder' => 'A small amount of text',
            'rows'        => 3,
            'required'    => 'required',
        ),
    ),
    

    Note that Carbon Fields and CMB2 handle the validation in different manner: CF uses javascript and CMB2 uses HTML5 required attribute.

    • This reply was modified 8 years, 3 months ago by htmlBurger. Reason: typo fix
Viewing 1 replies (of 1 total)
  • The topic ‘Field validation’ is closed to new replies.