Coder Social home page Coder Social logo

antonythorpe / dateinputfieldreader Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 1.77 MB

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.

License: MIT License

HTML 9.52% JavaScript 90.48%
jquery-ui datepicker date data-entry input-field

dateinputfieldreader's Introduction

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:

  • 23
  • 23/1
  • 23 1
  • 23-1
  • 23.1
  • 23 Jan
  • or 23/1/18(short year length) to generate Wed 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/23
  • 1 23
  • 1-23
  • 1.23
  • Jan 23

Also with year-first regions like Korea.

  • 18 Jan 23

Installation

npm install dateinputfieldreader

How 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

File

Licence

MIT

dateinputfieldreader's People

Contributors

antonythorpe avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.