Skip to content

multiple dates picker over 1 year and without arrows #276

@LECUYER-David

Description

@LECUYER-David

Hello everyone,

Thank you for your work and sharing the multiple dates pickes.

In my project with natuw, it was to offer a calendar starting from today's date over 1 year.
Unfortunately with multiple dates they offer us the arrows to go to the next month.

I share with you the code that I made to make exactly 1 year exact, avoiding the following arrows for the following months depending on the date of the day.

If this code can help someone, because I was having a bit of difficulty avoiding the arrows, I would be very happy.

Thanks again to all the people who contributed to creating the multiple dates picker, because it really helped me in my natuw project

Sincerely
david lecuyer

/start calendarr/
function calendar_view(){

$('#datepicker2').multiDatesPicker('resetDates');
var jours=document.getElementById('altField').value;
var today = new Date();
var y = today.getFullYear();
let dates_choix=false;
if (jours!=""){
jours=jours.replace(/ /g,'');//on retire les espaces
dates_choix = jours.split(",");
}

	var mois_en_cours=today.getMonth();
	var mois_precedent=today.getMonth()-1;
	var annee_en_cours=today.getFullYear();
	var annee_suivante=today.getFullYear()+1;

	var jours_en_cours=today.getDate();
	var der_jours=GetLastDayOfThisMonth(mois_precedent);

	var date_debut = new Date(annee_en_cours, mois_en_cours, jours_en_cours);
	var date_fin = new Date(annee_suivante,mois_precedent,der_jours);

	var result=datesDiff(date_debut, date_fin);

function datesDiff(a, b) {
a = a.getTime();
b = (b || new Date()).getTime();
var c = a > b ? a : b,
d = a > b ? b : a;
return Math.abs(Math.ceil((c - d) / 86400000));
}

function GetLastDayOfThisMonth (mois) {
var myDate = new Date ();
var myMonth = myDate.setMonth (mois+1);
var theDay = myDate.setDate (0);
var lastDay = myDate.getDate ();
return lastDay;

}

		$('#datepicker').multiDatesPicker({			
		addDates: dates_choix,			
		//maxPicks: 1,
		numberOfMonths: [nb_lignes,nb_col],	
		defaultDate: '1/1/'+y,
		altField: '#altField',
		minDate: 0,
		maxDate: result,					
		dateFormat : 'dd/mm/yy',
		firstDay : 1,
		dayNames : ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
		dayNamesMin : ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
		monthNames : ['Janvier', 'Fevrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Decembre'],
		timeOnlyTitle : 'Heure',
		timeText : '',
		hourText : 'Heure',
		minuteText : 'Minute',
		nextText : 'Suivant',
		prevText : 'Précédent',
		currentText : 'Heure actuelle',
		closeText : 'Valider'	
	});	

	//fin cache le calendar choix de date

}
/end calendar/

Metadata

Metadata

Assignees

No one assigned

    Labels

    ContributionsCode contributions for improvements and complex use-cases.Feature request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions