I have a field that uses flatpickr and I would like to obtain the date that I select, I don't know how to do it, try using onClick
This is the function that generates the calendar ej js:
function form__date_register() {
flatpickr('.js--input--date_register', {
minDate: '1920-01-01',
maxDate: 'today',
locale: {
firstDayOfWeek: 1,
weekdays: {
shorthand: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'],
longhand: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
},
months: {
shorthand: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Оct', 'Nov', 'Dic'],
longhand: ['Enero', 'Febrero', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
},
},
});
}
The following code is the input:
<div class="input_p__contenedor bloque--mitad">
<?= $this->Form->control('fecha_aplicacion', [
'class' => 'input_p__field js--input--date required',
'id' => 'form__aplicacion',
'onClick' =>'etapa_fase();',
'label' =>'Fecha de aplicación',
'placeholder' => 'Fecha de aplicación',
'data-enabletime' => true,
'templates' => [
'formGroup' => '{{input}}{{label}}'
],
'type' => 'text'
]) ?>
</div>
The following code is a function where I want to get the value:
function etapa_fase(){
var dateControl = document.querySelector('input[type="date"]');
$("#form__aplicacion").val();
alert( $("#form__aplicacion").val());
}
See guiding me from the Official Documentation . I made you an example. It's nothing to write home about, you just have to register the event in
form__date_register()
. In all plugins whether bootsrap, materialize, whatever...it's usually done this way. In the event callback I only print the data on the console, but you can easily send it toetapa_fase()
or perform the actions you need. Let me know if you have any questions, I hope I was clear. Cheers!You can use flatpickr's onChange event :
With this event you can get the value of the field with the dateStr parameter like this:
I hope it helps you.