How to clear all input fields in bootstrap modal when clicking data-dismiss button?
http://getbootstrap.com/javascript/#modals shows an event for when a modal is hidden. Just tap into that:
$('#modal1').on('hidden.bs.modal', function (e) {
$(this)
.find("input,textarea,select")
.val('')
.end()
.find("input[type=checkbox], input[type=radio]")
.prop("checked", "")
.end();
})
http://jsfiddle.net/5LCSU/
I would suggest the above as it bind the clearing to the modal itself instead of the close button, but I realize this does not address your specific question. You could use the same clearing logic bound to the dismiss buttons:
$('[data-dismiss=modal]').on('click', function (e) {
var $t = $(this),
target = $t[0].href || $t.data("target") || $t.parents('.modal') || [];
$(target)
.find("input,textarea,select")
.val('')
.end()
.find("input[type=checkbox], input[type=radio]")
.prop("checked", "")
.end();
})
http://jsfiddle.net/jFyH2/
Clear Bootstrap Modal Form after cancel button is clicked inside Modal
FormGroup
has a method called reset()
:
this.modalForm.reset();
You can read more about reset()
and FormGroup
itself in Angular 2 official documentation.
Form inside Boostrap Modal does not reset
After changing value of Select2
's underlying <select>
or <input>
you have to trigger change
event so this change will be handled by Select2
code and rendered appropriately:
$(".bulkAssignForm").find("select").val("").trigger("change");
Successfully tested on AutoForm Demo
test page.
Related Topics
Javascript Form Submit - Confirm or Cancel Submission Dialog Box
How to Look for Changes in Localstorage in Angular 4
How to Format and Display Json Data Using Array.Map in Reactjs
Refresh the Parent Component View in Angular 4
Javascript to Download a File from Amazon S3 Bucket
Running Functions One After Other in React
How to Format Numbers by Prepending 0 to Single-Digit Numbers
How to Redirect to Another Page Using Angularjs
Export Array of Objects into Excel Using JavaScript
Discord.Js Sending Message to Specific Channel
Lodash Group by Multiple Properties If Property Value Is True
Handle File Download from Ajax Post
Window.Opener | Not Working in Chrome
Replace All Chars With #, Except for Last 4
Violation Long Running JavaScript Task Took Xx Ms
Increase and Decrease Number With JavaScript and Two Buttons Up and Down