Hello, I am making a reservation system in which I need to show on my datepicker the dates that are occupied and those that are not.
the reservation table is like this (this summary)
CREATE TABLE if not exists reservas(
id_reserva integer(20) NOT NULL AUTO_INCREMENT,
id_cliente integer,
id_residencial integer(20),
id_habitacion integer(20),
llegada date,
salida date,
PRIMARY KEY (id_reserva),
FOREIGN KEY (id_cliente) REFERENCES clientes(id_cliente),
FOREIGN KEY (id_residencial) REFERENCES residenciales(id_residencial),
FOREIGN KEY (id_habitacion) REFERENCES habitaciones(id_habitacion)
) ENGINE=InnoDB;
in my form I have the arrival and departure input
<input style="height: 31px;" id="datepicker2" class="form-control" name="llegada" >
...
<input style="height: 31px;" id="datepicker3" class="form-control" name="salida">
and for the datepicker I have this code
<script>
$(function() {
var eventDates = {};
eventDates[ new Date( '12/04/2016' )] = new Date( '12/05/2016' );
eventDates[ new Date( '12/06/2016' )] = new Date( '12/06/2016' );
eventDates[ new Date( '12/20/2016' )] = new Date( '12/20/2016' );
eventDates[ new Date( '12/25/2016' )] = new Date( '12/25/2016' );
$( "#datepicker3" ).datepicker({
numberOfMonths:[2,2],
showButtonPanel: true,
firstDay: 1,
beforeShowDay: function( date ) {
var highlight = eventDates[date];
if( highlight ) {
return [true, "event", "highlight"];
} else {
return [true, '', ''];
}
}
});
});
</script>
<style type="text/css">
.event a {
background-color: rgba(244, 67, 54, 0.45) !important;
background-image :none !important;
color: #ffffff !important;
}
</style>
This shows me the calendar with the days in red, but the days that I defined already in the function:
eventDates[ new Date( '12/04/2016' )] = new Date( '12/05/2016' );
eventDates[ new Date( '12/06/2016' )] = new Date( '12/06/2016' );
eventDates[ new Date( '12/20/2016' )] = new Date( '12/20/2016' );
eventDates[ new Date( '12/25/2016' )] = new Date( '12/25/2016' );
So what I'm looking for is that from my table reservas
can get a range of dates between llegada
and salida
(previously already selected the id_habitacion
), and that range appears in red and can not be selected on the datepicker.
I searched and quite, but I could not gather or coordinate the information with my code. : /