Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset form body in bootstrap modal box?

I am looking for a way to clear all elements found within an HTML form contained inside a Bootstrap modal without refreshing the page.

Currently:

The user enters data and closes the modal.

When the user re-opens the modal, the previously entered data still remains.

How can I completely clear all elements within the form during the close event of the modal dialog so that when the user re-opens it, they always get fresh clean inputs & etc?

like image 980
Abdul Moeed Avatar asked Apr 05 '13 06:04

Abdul Moeed


People also ask

How do I reset a bootstrap modal form?

reset is dom build-in funtion, you can also use $(this). find('form')[0]. reset();

How do you clear form values?

You can easily reset all form values using the HTML button using <input type=”reset”> attribute. Clicking the reset button restores the form to its original state (the default value) before the user started entering values into the fields, selecting radio buttons, checkboxes, etc.

How do I delete a form after submitting?

To clear an input field after submitting:Add a click event listener to a button. When the button is clicked, set the input field's value to an empty string. Setting the field's value to an empty string resets the input.

What is a modal form in Bootstrap?

Bootstrap Modal Form Bootstrap modal forms are displayed-on-action pop-up forms that are used for gathering data from website visitors and to register or log users. Using them alongside valuable content might bring a lot of business value to your project.

How to reset form after modal window is closed in Bootstrap?

In Bootstrap 3 you can reset your form after your modal window has been closed as follows: $ ('.modal').on ('hidden.bs.modal', function () { $ (this).find ('form').reset (); });

How to change the size of the modal in Bootstrap JS?

Change the size of the modal by adding the .modal-sm class for small modals or .modal-lg class for large modals. Add the size class to the <div> element with class .modal-dialog: By default, modals are medium in size. For a complete reference of all modal options, methods and events, go to our Bootstrap JS Modal Reference.

What happens when the user re-opens the modal dialog?

When the user re-opens the modal, the previously entered data still remains. How can I completely clear all elements within the form during the close event of the modal dialog so that when the user re-opens it, they always get fresh clean inputs & etc?


1 Answers

In Bootstrap 3 you can reset your form after your modal window has been closed as follows:

$('.modal').on('hidden.bs.modal', function(){     $(this).find('form')[0].reset(); }); 
like image 111
bart Avatar answered Sep 19 '22 09:09

bart