Selezionare singoli giorni su datepiker

otto9due

Utente Attivo
22 Feb 2014
591
25
28
Come da titolo vi chiedo se qualcuno di voi sa come impostare il datepiker in modo tale da poter selezionare oltre che ad esempio tutte le domeniche ( cosa che sono riuscito a fare ) anche alcuni giorni spuri, contenui ad esempio in un array )

Ho fatto, aiutandomi con un esempio, una cosa del genere, che non funziona totalmnte però.. Qualche idea?
HTML:
/* Datapiker */

jQuery(document).ready(function ($) {
    //Data di oggi e setto inizio primo datepiker
    var now = new Date();
    var today = now.getDate() + '/' + (now.getMonth() + 1) + '/' + now.getFullYear();
    $('#datepicker').val(today);
});

/* Datapiker 1 */

jQuery(document).ready(function ($) {
    //Data di domani e setto inizio secondo datepiker

    var now = new Date();
    var today = now.getDate() + 1 + '/' + (now.getMonth() + 1) + '/' + now.getFullYear();

    $('#datepicker1').val(today);
});


// DA QUI IN POI NON VA COME SPERATO


/* Datapiker format*/
var availableDates = [
    new Date(2017, 7, 12),
    new Date(2017, 7, 27),
    new Date(2017, 7, 14)
];

function available(date) {
    if (date.getDay() === 0 && $.inArray(date.getDay(), availableDates)) {
        return [true, ""];     
    } else {
        return [false, "", "Unavailable"];
    }
}

jQuery(document).ready(function ($) {
    // Setter
    $("#datepicker, #datepicker1").datepicker({
        beforeShowDay: available,
        "dateFormat": "dd/mm/yy",
        "showAnim": "slideDown",
        "showButtonPanel": true,
        "firstDay": 1,
        "minDate": 0
    });
});

jQuery(document).ready(function ($) {
    $("#datepicker").change(function(){
    //Aggiungo 3gg alla data selezionata
        var currentDate = $(this).datepicker('getDate');
        currentDate.setDate(currentDate.getDate() + 7);
        $("#datepicker1").datepicker('setDate', currentDate);
        $("#datepicker1").datepicker( "destroy" ); //distruggo
        $("#datepicker1").datepicker({ beforeShowDay: function (dt) {return [dt.getDay() == 0, ""];},minDate: currentDate, maxDate: "", dateFormat: "dd/mm/yy", showButtonPanel: true, "firstDay": 1 });//reinizializzo con range data
    });//CHANGE
});
Grazie in anticipo.
 
Ok ho trovato la soluzione girando un pò online.. eccola:
HTML:
var availableDates = ["9-7-2017","14-7-2017","15-7-2017"];

function available(date) {
  dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
  if (date.getDay() === 6 || $.inArray(dmy, availableDates) != -1) {
    return [true, "","Available"];
  } else {
    return [false,"","unAvailable"];
  }
}

$('#date').datepicker({ beforeShowDay: available });
In questo caso saranno selezionabili solo le domeniche e alcuni giorni spuri inseriti nell'array.
Spero serva ad altri ;) a presto
 

Discussioni simili