Issue
Very novice problem, I just want to know how I can get the values of the selected dates in a Kalendae calendar using the getSelected() function. I need to store the values in a variable after they are selected.
I'm using multiple select calendar and I'm trying to record the dates selected but can't seem to get the values, I tried to put it in a var but I think I am not doing it correctly.
<html>
<head>
<title>Date Select</title>
<link rel="stylesheet" href="build/kalendae.css" type="text/css" charset="utf-8">
<script src="build/kalendae.standalone.js" type="text/javascript" charset="utf-8">
<style type="text/css" media="screen">
.kalendae .k-days span.closed {
background:red;
}
</style>
</head>
<body onload="getDate()">
<center>
<h4>Pick a date.</h4>
<div id="myDiv" class="auto-kal" data-kal="months:1, mode:'multiple'"></div>
<script>function getDate(){
var k = new Kalendae('myDiv');
k.subscribe('change', function (date) {
console.log(date, this.getSelected());
});
}<script>
</center>
</body>
</html>
I expect to get values like:
- 2/5/2019
- 2/7/2019
- 2/9/2019
After selecting, but I don't even get any result.
Solution
For me this code does what you want. You have multiple problems. I tried to explain it in comments:
<html>
<head>
<title>Date Select</title>
<link rel="stylesheet" href="build/kalendae.css" type="text/css" charset="utf-8">
<script src="build/kalendae.standalone.js" type="text/javascript" charset="utf-8">
</script> //Here you have to add closing script Tag
<style type="text/css" media="screen">
.kalendae .k-days span.closed {
background: red;
}
</style>
</head>
<body>
<center>
<h4>Pick a date.</h4>
<!-- If you use class="auto-kal" the kalendae library generates a new Kalendae
that does not have anything to do with your generated Kalendae object below. So
you have to add a div with the ID myDiv that you are using in new
Kalendae('myDiv'). If you want to understand this you can add "<div class="auto-
kal" data-kal="months:1, mode:'multiple'"> </div> " and you see two calendars
-->
<div id="myDiv" class="myDiv"></div>
<script>
//You doesn't have a Div HTML-Tag with myDiv - Id so
//this Kalendae was never displayed.
//Especially your function getDate() was never called. So this code
//never runs.
var k = new Kalendae('myDiv', {
months:1,
mode:'single',
selected:Kalendae.moment().subtract({M:1})
});
k.subscribe('change', function (date) {
console.log(date, this.getSelected());
});
</script>
</center>
</body>
</html>
I hope this helps you
Answered By - camen6ert
Answer Checked By - Robin (JavaFixing Admin)