[ jQuery ] How to prevent the modal from closing when using the data picker while using the bootstrap model.

JooKit 주킷 2022. 1. 12. 17:23
목차 접기
728x90
반응형

On the page, a datepicker is used in the element using the modal.
There was a problem that the modal was closed every time I clicked on a date on the datepicker's calendar.

 

 

 

$('#test').datepicker({
		format: "yyyy-mm-dd",
		autoclose: true
});

 

The above code is an existing code with datepicker set.

 

 

 

 

 

Below is a code to prevent the modal from closing when the date is selected with the datepicker in the modal.

$('#test').datepicker({
		format: "yyyy-mm-dd",
		autoclose: true
	}).on('hide', function(e){
		e.stopPropagation();
	});

 

 

 

 

 

Below is a function for generating an event before the modal closes.

	$('#test_modal').on('hide.bs.modal', function (e) {
		alert('Notification before the modal closes!!');
		e.preventDefault();
	});

 

 

 

 

 

 

Below, let's develop it by referring to the event type that can be used for events before and after opening and closing the modal.

event type descr
show.bs.modal It is an event that runs immediately when the modal opens.
shown.bs.modal It is an event that runs after the modal opens.
hide.bs.modal It is an event that runs immediately when the modal closes.
hidden.bs.modal This is an event that runs after the modal closes.

 

 

 

728x90
반응형
LIST