condition of days to show boostrap datepicker

0

I have the following problem: I have a list of services and each service has a production time, for example:

Service 1 - > 7 Days Habiles.
Service 2 - > 5 Daily Days.

This list comes from Mysql through a SELECT nested by ajax. What I need, is that depending on the service and its number of days of production time, these (days) are added to the datepicker as days that can not be selected. For example, if today is April 3, 2018 and the selected service has 7 working days, it is not possible to select a date less than these 7 days and the days must not be counted on Saturdays or Sundays. Currently, I already have blocked the days of Saturday and Sunday in my datepicker (it's not a big deal, but it's information you should know). File that returns the query by ajax of the select:

$consulta = mysql_query("SELECT * FROM hijos WHERE id_cliente = ".$id1."");
echo "<select name='tratamiento' class='form-control select2' >";
echo "<option value='0' selected='selected' disabled='disabled'>Elija Tratamiento</option>";
    while($registro = mysql_fetch_row($consulta))
        {
        echo "<option value='".$registro[0]."'>".$registro[1]." --> Tiempo Estimado Entrega: ".$registro[5]." a ".$registro[6]." Días Hábiles</option>";
    }
echo "</select>";

? >

Select HTML:

<div class="form-group m-b-15">
 <label class="control-label">Seleccione Tratamiento</label>
  <select name="subcategory" class="form-control select2" id="subcategory" >
   <option value='' selected='selected'>Seleccione Tratamiento</option>
  </select>
<span class="help-block" id="error"></span>                                                 
</div>

Date Picker content:

.datepicker({
  format: 'dd/mm/yyyy',
  autoclose: 'true',
  language: 'es',
  daysOfWeekDisabled: [0, 6],
  startDate : currDate
})

If anyone has any notion of how to do this, I would greatly appreciate it. Greetings and thanks to all of you for your information.

    
asked by maha1982 04.04.2018 в 04:32
source

1 answer

0

With the beforeShowDate option of datepicker.

This option gives you to choose whether the day represented is selectable or not, an additional css class and a popup tooltip to show something that day.

This option goes through each day of the calendar from starDate to about 2 more months

link

$( "#datepicker" ).datepicker({
    beforeShowDay: function(date){
    var selectable = true;
    // Comprobar que el date que me da datepicker
    // es igual a la fecha que yo quiero hacer no seleccionable
    if(date === myDate){
        selectable = false;
    }
    return [selectable, "", ""];
  }
});

Be careful with the comparison of dates because you probably have it in one format and beforeShowDay is in another date format.

    
answered by 04.04.2018 в 08:41