Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
Append jQueryUI datepicker to div (wrong display position)

I'm using jQueryUI datepicker on an input, and as default jQueryUI appends the #ui-datepicker-div to the body of the document.

The input in question is in a "popup" div on the screen, meaning any click outside of that div will close the "popup".

Because jQueryUI is appending the datepicker to the body, when I click on the datepicker the "popup" disappears... so I've tried moving it into the popup using the (currently) unaccepted answer on this question...

$("#myInput").datepicker({
  ...
  beforeShow: function() {
    $("#ui-datepicker-div").appendTo($("#myPopupDiv"));
  }
});

The problem is that jQueryUI then sets the top and left CSS style onthe #ui-datepicker-div based on a position relative to the body... but I need it to be relative to the "popup" div.

I've tried setting position:relative to #myPopupDiv. And I've also tried setting top and left as part of the beforeShow, but those values are immediately overwritten.

Is there anyway to make it position correctly?

Please see the following simple example, where the input is at 50px/100px, but the datepicker now appears at 100px/200px...

$("input").datepicker({
  beforeShow: function() {
    $("#ui-datepicker-div").appendTo($("#myPopup"));
  }
});
#myPopup {
  position:absolute;
  top:50px;
  left:100px;
}
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<div id="myPopup">
  <input>
</div>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The position of the singleton can be set with $.datepicker._pos = [x, y].

However, each time the datepicker dialog shows up, it sets the _pos to null and therefore recalculates the position at the subsequent use.

In your case, the following would set the position each time before opening.

$("input").datepicker({
    beforeShow: function() {
        $.datepicker._pos = [20, 0];
        $("#ui-datepicker-div").appendTo($("#myPopupDP"));
    }
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda