Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple dates picker over 1 year and without arrows #276

Open
LECUYER-David opened this issue Aug 15, 2024 · 0 comments
Open

multiple dates picker over 1 year and without arrows #276

LECUYER-David opened this issue Aug 15, 2024 · 0 comments

Comments

@LECUYER-David
Copy link

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant