Labels should include required info, when it's a required field

Support MB Frontend Submission Labels should include required info, when it's a required fieldResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #17282
    flowdeeflowdee
    Participant

    When setting a field to "required", on the frontend submission form, the label should represent this state as well.

    e.g. by holding a litte span like <span class="req">*</span>. If you don't need it, you could easily hide it via CSS.

    https://prnt.sc/q4wsia

    #17283
    flowdeeflowdee
    Participant

    Temporarily solved it wthis way:

    /**
     * Maybe add required span to labels
     */
    add_filter( 'rwmb_begin_html', function ( $begin, $field, $meta ) {
     
        if ( is_admin() )
            return $begin;
     
        if ( ! empty ( $field['required'] ) ) {
            $begin = str_replace( '</label>', '<span class="req">*</span></label>', $begin );
        }
     
        return $begin;
    }, 10, 3 );

    Additional question: Tried to apply this hook only to the frontend submission fields, by using filters/prefixes like rwmb_frontend_begin_html, mb_frontend_begin_html, rwmb_mb_frontend_begin_html but none of them worked.

    #17316
    Anh TranAnh Tran
    Keymaster

    Hi,

    This is fixed.

    Your filter also works. If you want to make it work only on the front end, you need to check with is_admin() function. There is no filters like rwmb_frontend_*.

    #17319
    flowdeeflowdee
    Participant

    Perfect, thanks!

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