-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Format as a parameter in callbacks
Added Format as a parameter in `parseDateTimeString` and `formatDateTimeString` callbacks to let it support different formats. Previously, with this function parsing or formatting of only one format was possible. Now based on format different code can be written for parsing or formatting the date. ``` parseDateTimeString: function(sDateTime, sMode, sFormat, oInputElement) { } ``` ``` formatDateTimeString: function(oDate, sMode, sFormat, oInputElement) { } ``` Added exmaple in which date format of date string in input field is different from the date format of date string to be displayed on DateTimePicker, as requested in #125 Added exmaple for using different date formats for storing date in the database and displaying on DateTimePicker, as requested in #122
- Loading branch information
Showing
51 changed files
with
280 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<!DOCTYPE html> | ||
|
||
<html> | ||
|
||
<head> | ||
|
||
<title>Custom Input Value</title> | ||
|
||
<link rel="stylesheet" type="text/css" href="../src/DateTimePicker.css" /> | ||
|
||
<script type="text/javascript" src="jquery-1.11.0.min.js"></script> | ||
<script type="text/javascript" src="../src/DateTimePicker.js"></script> | ||
|
||
<!--[if lt IE 9]> | ||
<link rel="stylesheet" type="text/css" href="../src/DateTimePicker-ltie9.css" /> | ||
<script type="text/javascript" src="../src/DateTimePicker-ltie9.js"></script> | ||
<![endif]--> | ||
|
||
<style> | ||
|
||
p | ||
{ | ||
margin-left: 20px; | ||
} | ||
|
||
input | ||
{ | ||
width: 200px; | ||
padding: 10px; | ||
margin-left: 20px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.btn | ||
{ | ||
background: #FFFFFF; | ||
color: #A3A3CC; | ||
|
||
border: 2px solid #A3A3CC; | ||
border-radius: 5px; | ||
|
||
padding: 10px 20px; | ||
margin: 20px; | ||
|
||
font-size: 12px; | ||
|
||
cursor: pointer; | ||
} | ||
|
||
</style> | ||
|
||
</head> | ||
|
||
<body> | ||
|
||
<p>Date : </p> | ||
<input id="input-date" type="text" data-field="date" data-format="dd-MM-yyyy" value="2016-07-05" readonly> | ||
|
||
<div id="dateBox"></div> | ||
|
||
<script type="text/javascript"> | ||
|
||
$(document).ready(function() | ||
{ | ||
var oDTP1; | ||
|
||
$("#dateBox").DateTimePicker( | ||
{ | ||
addEventHandlers: function() | ||
{ | ||
oDTP = this; | ||
|
||
oDTP.settings.maxDate = oDTP.getDateTimeStringInFormat("date", "dd-MM-yyyy", new Date()); | ||
}, | ||
|
||
parseDateTimeString: function(sDateTime, sMode, sFormat, oInputElement) | ||
{ | ||
oDTP1 = this; | ||
|
||
console.log(sDateTime + " " + sMode); | ||
var dThisDate = new Date(), | ||
iArrDateTimeComps, sRegex; | ||
|
||
if($.cf._isValid(sDateTime)) | ||
{ | ||
// "2016-10-26" | ||
sRegex = /(\d{1,4})(-)(\d{1,2})(-)(\d{1,2})/; | ||
|
||
iArrDateTimeComps = sDateTime.match(sRegex); | ||
|
||
|
||
dThisDate = new Date( | ||
parseInt(iArrDateTimeComps[1]), | ||
parseInt(iArrDateTimeComps[3]) - 1, | ||
parseInt(iArrDateTimeComps[5]), | ||
0, 0, 0, 0 | ||
); | ||
} | ||
|
||
return dThisDate; | ||
}, | ||
|
||
formatDateTimeString: function(oDate, sMode, sFormat, oInputElement) | ||
{ | ||
oDTP1 = this; | ||
|
||
console.log("formatDateTimeString " + sFormat); | ||
console.log(oDate); | ||
if(sFormat === "yyyy-MM-dd") | ||
return oDate.yyyy + "-" + oDate.MM + "-" + oDate.dd; | ||
else if(sFormat === "dd-MM-yyyy") | ||
return oDate.dd + "-" + oDate.MM + "-" + oDate.yyyy; | ||
} | ||
}); | ||
}); | ||
|
||
</script> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<!DOCTYPE html> | ||
|
||
<html> | ||
|
||
<head> | ||
|
||
<title>Basic Examples - Set DateTime In Input Field</title> | ||
|
||
<link rel="stylesheet" type="text/css" href="../src/DateTimePicker.css" /> | ||
|
||
<script type="text/javascript" src="jquery-1.11.0.min.js"></script> | ||
<script type="text/javascript" src="../src/DateTimePicker.js"></script> | ||
|
||
<!--[if lt IE 9]> | ||
<link rel="stylesheet" type="text/css" href="../src/DateTimePicker-ltie9.css" /> | ||
<script type="text/javascript" src="../src/DateTimePicker-ltie9.js"></script> | ||
<![endif]--> | ||
|
||
<style type="text/css"> | ||
|
||
p | ||
{ | ||
margin-left: 20px; | ||
} | ||
|
||
input | ||
{ | ||
width: 200px; | ||
padding: 10px; | ||
margin-left: 20px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
</style> | ||
|
||
</head> | ||
|
||
<body> | ||
|
||
<p>Date : </p> | ||
<input type="text" data-field="date" data-format="dd-MM-yyyy" readonly> | ||
|
||
<div id="dtBox"></div> | ||
|
||
<script type="text/javascript"> | ||
|
||
var inputDateString = "2016-10-22", outputDateString, dDateTime; | ||
|
||
$(document).ready(function() | ||
{ | ||
$("#dtBox").DateTimePicker( | ||
{ | ||
|
||
addEventHandlers: function() | ||
{ | ||
oDTP = this; | ||
var inputDateStringComp = inputDateString.split("-"); | ||
|
||
// Set Date | ||
oDTP.settings.defaultDate = new Date(parseInt(inputDateStringComp[0]), parseInt(inputDateStringComp[1]) - 1, parseInt(inputDateStringComp[2]), 0, 0, 0, 0); | ||
dDateTime = new Date(oDTP.settings.defaultDate); | ||
|
||
oDTP.setDateTimeStringInInputField($("input"), oDTP.settings.defaultDate); | ||
}, | ||
|
||
settingValueOfElement: function(sElemValue, dElemValue, oElem) | ||
{ | ||
oDTP = this; | ||
|
||
if(oDTP.settings.mode === "date") | ||
{ | ||
dDateTime = new Date(dElemValue.getFullYear(), dElemValue.getMonth(), dElemValue.getDate(), 0, 0, 0, 0); | ||
|
||
outputDateString = oDTP.getDateTimeStringInFormat("date", "yyyy-MM-dd"); | ||
} | ||
|
||
console.log(dDateTime + " -- " + outputDateString); | ||
} | ||
}); | ||
}); | ||
|
||
</script> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.