1.0.0 • Published 8 years ago
dateinputfieldreader v1.0.0
Date Input Field Reader for jQuery UI Datepicker
Sneaky shortcuts for date input field data entry with jQuery UI datepicker in any locale. Provides a better UX by allowing the user to select either the input field or the datepicker.
Usage
The user can enter:
2323/123 123-123.123 Jan- or
23/1/18(short year length) to generateWed Jan 03 2018 00:00:00 GMT+1300 (NZDT)date string.
If you are from a funny country that places the month first then this will work too:
1/231 231-231.23Jan 23
Also with year-first regions like Korea.
18 Jan 23
Installation
npm install dateinputfieldreaderHow to use
- ensure that jQuery UI Datepicker is loaded first
- import the function:
import extractDateFromInput from "dateinputfieldreader";and within the change event of the datepicker run the data entry through this function. Below is some knockoutjs code you can modify:
//handle the field changing update observable and excluded dates for beforeShowDay
ko.utils.registerEventHandler(element, "change", function(event) {
var enteredDate = (event.target.value).trim();
var extractedDate = extractDateFromInput(enteredDate);
if (extractedDate){
// next update the variable
observable(extractedDate);
// and update the datepicker
$(element).datepicker("setDate", extractedDate);
}
});Requirements
Tests
Run online here.
Locally npm test to launch in Chrome.
Contributions
Pull requests are most welcome!
Support
None sorry.
Change Log
Licence
1.0.0
8 years ago