Custom Fields
Re-Envisioned
Support MB Settings Page Clear Field value with Reset Button

This topic contains 1 reply, has 2 voices, and was last updated by  Anh Tran 2 weeks ago.

  • Creator
    Topic
  • #16708
    Resolved
    Manoj Kumar
    Participant

    Hello,

    I need to clear my meta box field values using the Reset button on the setting page. Is there any solution to accomplish this

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #16760

    Anh Tran
    Keymaster

    Hi Manoj,

    The reset functionality is not built-in. You can add the following code into your theme’s functions.php file to add the reset button:

    add_action( 'mb_settings_page_submit_buttons', function() {
        submit_button( 'Reset', 'secondary', 'reset', false );
        ?>
        <script>
            jQuery( function( $ ) {
                $( '#reset' ).on( 'click', function( e ) {
                    e.preventDefault();
                    $( 'input[type="text"]' ).val( '' ); // Clear input values
                    $( 'input[type="radio"],input[type="checkbox"]' ).prop( 'checked', false ); // Uncheck radio, checkbox
                } );
            } );
        </script>
        <?php
    } );

    The JS code is very basic and is just an idea how it works for basic fields. You might need to adjust it to make it work for other fields.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.