Custom Fields
Re-Envisioned
Support Meta Box Builder HTML Type pattern=”d{3}-d{3}-d{3}

  • Creator
    Topic
  • #23867
    Resolved jw_bln
    Participant

    I added a “text field” to custom fields group and in the advanced-tab of it I added a “custom attributes” and filled the two fields with “pattern” and “d{3}-d{3}-d{3}”.
    But by entering 123-123-123 in admin an error shows up: Invalid format.

    What is missing or wrong?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #23872
    Long Nguyen
    Moderator

    Hi,

    You can use this pattern to validate 3 numbers and a hyphen between [0-9]{3}-[0-9]{3}-[0-9]{3}. See more on this guide: https://www.html5pattern.com/Postal_Codes.

    #23890
    jw_bln
    Participant

    Unfortunately also not working (same error-message / red field) – please can you show an example of how it works in the graphical UI?
    As no pictures are possible to add, I can not show the result – only describe it…
    I am doing it in “Taxonomies = category”.

    Copde generated:

    <?php
    add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
    
    function your_prefix_register_meta_boxes( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'      => esc_html__( 'Category_Order', 'text-domain' ),
            'id'         => 'Category_order',
            'fields'     => [
                [
                    'id'            => $prefix . 'M_category-orderID',
                    'type'          => 'number',
                    'name'          => esc_html__( 'Category Order ID', 'text-domain' ),
                    'required'      => 1,
                    'tooltip'       => 'defines order priority',
                    'admin_columns' => [
                        'position' => 'before name',
                        'sort'     => true,
                    ],
                ],
                [
                    'id'      => $prefix . 'text_sb532j9yqc',
                    'type'    => 'text',
                    'name'    => esc_html__( 'Text Field', 'text-domain' ),
                    'pattern' => '[0-9]{3}-[0-9]{3}-[0-9]{3}',
                ],
            ],
            'taxonomies' => ['category'],
        ];
    
        return $meta_boxes;
    }
    #23922
    Long Nguyen
    Moderator

    Hi,

    The pattern in your code works as well on my local site, see this screen record https://share.getcloudapp.com/wbuKO5B5.

    Please try to check this case in another browser such as Edge or Firefox.

    #24219
    jw_bln
    Participant

    Can be closed, thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.