Datepicker bootstrap in Python (Django)

0

The basic implementation of the Bootstrap Datepicker works correctly, what does not work is the datesDisabled (deactivate dates):

My forms.py:

class BookForm(forms.ModelForm):
class Meta:
    dateTimeOptions = {
    'format': 'dd/mm/yyyy',
    'autoclose': True,
    'startDate': datetime.now().strftime("%d/%m/%Y"),
    'datesDisabled': ['20/02/2017']
    }

    model = Reserva
    fields = ['fecha_entrada','fecha_salida']   
    widgets = {
        'fecha_entrada': DateWidget(attrs={'id':"start",'readonly':'readonly','class':'datepicker'}, usel10n = True, bootstrap_version=3, options = dateTimeOptions),
        'fecha_salida': DateWidget(attrs={'id':"end",'readonly':'readonly','class':'datepicker'}, usel10n = True, bootstrap_version=3, options = dateTimeOptions)
    }

Basically what this form does is insert a script for each input so that:

<script type="text/javascript">
           $("#start").datetimepicker({format: 'dd/mm/yyyy',
           autoclose: true,
           startDate: '28/01/2017',
           startView: 2,
           minView: 2,
           language: 'es'}).find('input').addClass("form-control");
</script>

This script is what requires Bootstrap in .html for its operation. The problem arises when I insert the datesDisabled: ['20/02/2017'] for example, as put the Bootstrap documentation and it seems that he does not care, no kind of error, he just does not read it. I have latest version of Bootstrap, JavaScript and jQuery.

    
asked by Jota 28.01.2017 в 21:23
source

2 answers

0

Good morning

I do not see the datesDisabled in the Javascript code, but a priori the difference I see is that the two points would be missing.

<script type="text/javascript">
           $("#start").datetimepicker({format: 'dd/mm/yyyy',
           autoclose: true,
           startDate: '28/01/2017',
           datesDisabled: ['20/02/2017'],
           startView: 2,
           minView: 2,
           language: 'es'}).find('input').addClass("form-control");
</script>

I hope it helps you

    
answered by 30.01.2017 в 12:35
0

Let's see if putting it in this other way we make it work:

var disableddates = ["20-02-2017", "21-02-2017"];

function DisableSpecificDates(date) {
    var string = jQuery.datepicker.formatDate('dd-mm-yy', date);
    return [disableddates.indexOf(string) == -1];
  }

$("#start").datepicker({beforeShowDay: DisableSpecificDates});

I hope it helps you

    
answered by 01.02.2017 в 11:48