Effect on jQuery does not work with datepicker

Asked

Viewed 122 times

3

Galera mounted an input with an effect, which occurs when entering a value in the input, the problem and that the same effect does not work using the Picker data in the input. That is when you put a date the effect does not occur, getting text on top of the date.

Someone knows how to fix 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>

  • Look at my answer.

1 answer

2


It happens because you lose the focus in 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 make a slight impression there. See if it fits.

$('.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>

  • 1

    Ok worked 100% here. Thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.