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

    (@tw2113)

    The BenchPresser

    It’s nothing specific to CMB2, but you could pass in the a maxlength attribute to be appended to the field input. https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes

    Thread Starter wpfan1000

    (@wpfan1000)

    Thanks!
    Marking as resolved

    Hey Michael,

    Just wondering – how would I go about passing the maxlength attribute to be appended to the field input? Not sure where to start.

    Thanks!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    ogdsgn, this will work on text inputs, despite the example being a textarea.

    $cmb->add_field( array(
        'name'        => 'Extra Small Textarea',
        'id'          => 'wiki_test_xtra_small_textarea',
        'type'        => 'textarea_small',
        'attributes'  => array(
            'placeholder' => 'A small amount of text',
            'rows'        => 3,
            'required'    => 'required',
        ),
    ) );

    Note the “attributes” portion. You can add extra html attributes to ANY of the field types like this, including maxlengh.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Limit number of characters per text field’ is closed to new replies.