javascript – Effect in jQuery doesn't work with datepicker

Question:

Guys I set up an input with an effect, which occurs when inserting a value into the input, the problem is that the same effect doesn't work using the data picker on the input. In other words, when you put a date, the effect does not occur, text is left on top of the date.

Does anybody know how to solve this?

$('.data').datepicker({
  'autoclose': true
});
$('.form_campos').on('focus blur', function(e) {
  $(this).parents('.form-group').toggleClass('focused', (e.type === 'focus' || this.value.length > 0));
}).trigger('blur');
.form-group {
  margin-top: 20px;
  position: relative;
  display: flex;
  height: 45px;
  float: left;
}
.control-label {
  opacity: 0.4;
  pointer-events: none;
  position: absolute;
  transform: translate3d(5px, 22px, 0) scale(1);
  transform-origin: left top;
  transition: 240ms;
  z-index: 2;
}
.form-group.focused .control-label,
.form-group-select.focused .control-label {
  opacity: 1;
  transform: scale(0.75);
}
.form_campos {
  height: 31px;
  width: 100%;
  color: #484848;
  z-index: 1;
  align-self: flex-end;
  padding: 5px;
  outline: none;
  border: 0 solid #484848;
  border-bottom-width: 1px;
  background: transparent;
}
.form_campos:hover,
.form_campos:focus {
  border-color: #0091FF;
}
.form_disabled,
.form_disabled:hover,
.form_disabled:focus {
  border-color: #D7D7D7;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>


<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>

<div class='form-group'>
  <label class='control-label' for='inputNormal'>DATA</label>
  <input type='text' class='efeito_input efeito_input form_campos data' id='inputNormal' name='validade'>
</div>

Answer:

This happens because you lose focus on the input, one of the solutions can be to make a focus :

$('.data').datepicker({
  'autoclose': true,
}).on('hide', function(e) {
    $(this).parents('.form-group').toggleClass('focused', (e.type === 'focus' || this.value.length > 0));
});

Working here, but it makes a slight impression there. See if it serves.

$('.data').datepicker({
  'autoclose': true,
}).on('hide', function(e) {
    $(this).parents('.form-group').toggleClass('focused', (e.type === 'focus' || this.value.length > 0));
});

$('.form_campos').on('focus blur', function(e) {
  $(this).parents('.form-group').toggleClass('focused', (e.type === 'focus' || this.value.length > 0));
}).trigger('blur');
.form-group {
  margin-top: 20px;
  position: relative;
  display: flex;
  height: 45px;
  float: left;
}
.control-label {
  opacity: 0.4;
  pointer-events: none;
  position: absolute;
  transform: translate3d(5px, 22px, 0) scale(1);
  transform-origin: left top;
  transition: 240ms;
  z-index: 2;
}
.form-group.focused .control-label,
.form-group-select.focused .control-label {
  opacity: 1;
  transform: scale(0.75);
}
.form_campos {
  height: 31px;
  width: 100%;
  color: #484848;
  z-index: 1;
  align-self: flex-end;
  padding: 5px;
  outline: none;
  border: 0 solid #484848;
  border-bottom-width: 1px;
  background: transparent;
}
.form_campos:hover,
.form_campos:focus {
  border-color: #0091FF;
}
.form_disabled,
.form_disabled:hover,
.form_disabled:focus {
  border-color: #D7D7D7;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>


<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>

<div class='form-group'>
  <label class='control-label' for='inputNormal'>DATA</label>
  <input type='text' class='efeito_input efeito_input form_campos data' id='inputNormal' name='validade'>
</div>
Scroll to Top