2
I’m using the plugin datepicker
All my datepicker input, has the class called datepicker
<input type="text" class="datepicker">
So, I have only one configuration for datepicker and can use on all pages, so I do the configuration in a file dateconfig.js
, in that file I only have the following code:
$(".datepicker").datepicker({
dateFormat: 'dd/mm/yy',
dayNames: ['Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado','Domingo'],
dayNamesMin: ['D','S','T','Q','Q','S','S','D'],
dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sáb','Dom'],
monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez']
});
But I have a page with a table
and in it there is the input
with the class="datepicker"
But when I call a modal via ajax, and in it there is also a input
, it does not load the plugin, so on the page of this modal I copy the configuration code and add inside a tag <script>
//Configuration code cited above </script>
, doing this he adds the plugin, but there on my page with the table
, he doubles the plugin
, creating 2 calendars of datepicker
How could I solve these two problems?
Edit
The way I currently make the call of the modal is this:
in my "index/grid/table"
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content" id="modalContent">
</div>
</div>
</div>
my call from ajax
, I used a html helper
of asp.net mvc
, but I believe he interprets himself as this call from jquery
:
$.ajax({
type: "GET",
url: "URL",
success: function (result) {
$("#modalContent").html(result);
},
complete: function (msg) {
$('#myModal').modal('show');
}
});
What code are you using to open the modal?
– Sergio
@Sergio edited the question, it’s like this...
– Rod
Okay, I’m leaving work right now I’ll look over here, but why don’t you join
$("#modalContent .datepicker").datepicker({
within thatcomplete: function (msg) {
AJAX. So it will only add datepicker to this input(s) that the modal has received.– Sergio
@Sergio, but every ajax request, I will have to do this? becomes the code of a simple repetitive "get"
– Rod