Clear Field value with Reset Button

Support MB Settings Page Clear Field value with Reset ButtonResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #16708
    Manoj KumarManoj 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

    #16760
    Anh TranAnh 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 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.