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

98
Visualizações
Toggle input type for date and password

I have 3 disabled input fields and I want to remove password type on hover, but the date is not consistent, it doesn't change to password when I hover over the input field directly. The text works fine. I wonder why it acts like this and how it can be fixed

$('[data-masked="text-container"]').on('mouseenter', function() {
    $(this).children('input').attr("type", "text");
})

$('[data-masked="text-container"]').on('mouseleave', function() {
    $(this).children('input').attr("type", "password");
})

$('[data-masked="date-container"]').on('mouseenter', function() {
    $(this).children('input').attr("type", "date");
})

$('[data-masked="date-container"]').on('mouseleave', function() {
    $(this).children('input').attr("type", "password");
})
div {
  background: red;
  margin-top: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div data-masked="text-container">
  <input type="password"
         disabled
         value="hello">
</div>
<div data-masked="text-container">
  <input type="password"
         disabled
         value="yooooo">
</div>
<div data-masked="date-container">
  <input type="password"
         disabled
         value="2013-01-08">
</div>

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

0

A bit of experimentation with console.log() showed that the event handlers were not being reliably triggered for the date-type input. Thinking about what is different between a text input and a date input, well obviously the date input includes all kinds of fancy date-related stuff that the browser renders, some of which is dependent on mouse clicks and position. So presumably something about that is interfering with the normal mouseover handlers.

From there it was a simple bit of searching to find this answer which describes how to disable much of that fancy date-input related stuff - by using this CSS:

pointer-events: none !important;

And adding that to your example code solves the problem.

$('[data-masked="text-container"]').on('mouseenter', function() {
    $(this).children('input').attr("type", "text");
})

$('[data-masked="text-container"]').on('mouseleave', function() {
    $(this).children('input').attr("type", "password");
})

$('[data-masked="date-container"]').on('mouseenter', function() {
    $(this).children('input').attr("type", "date");
})

$('[data-masked="date-container"]').on('mouseleave', function() {
    $(this).children('input').attr("type", "password");
})
div {
  background: red;
  margin-top: 10px;
}
input[type=date] {
    color: blue; /* just to confirm our css is being applied */
    pointer-events: none !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div data-masked="text-container">
  <input type="password"
         disabled
         value="hello">
</div>
<div data-masked="text-container">
  <input type="password"
         disabled
         value="yooooo">
</div>
<div data-masked="date-container">
  <input type="password"
         disabled
         value="2013-01-08">
</div>

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