Giter Site home page Giter Site logo

luverolla / js-datepicker Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.34 MB

Pure JavaScript component that implements an interactive and accessible date picker with keyboard navigation

License: MIT License

CSS 10.27% JavaScript 89.73%
js-datepicker keyboard-shortcuts javascript accessible html-css-javascript html5 css3 flexbox html-component html-components datepicker-component datepicker-dialog datepicker-custom-component datepicker picker multilanguage multilanguage-support vanilla-js vanilla-javascript

js-datepicker's Introduction

JS Datepicker

Pure JavaScript (VanillaJS) component that implements an interactive date picker

How to use

To use the datepicker plugin, two main file must be included. The stylesheet:

<link rel="stylesheet" href="/js-datepicker/dist/css/jdatepicker.min.css" />

And the script file (inclusive of all language files)

<script src="/js-datepicker/dist/jdatepicker.min.js"></script>

The component must follow this structure

<input name="mydate" data-replace="datepicker" data-locale="en" data-format="d/m/y"
       data-mindate="1/1/2000" data-maxdate="31/12/2000" data-disableddates="5/2/2000,7/5/2000" />

Referencing

Once a jdatepicker has been istantiated, it can be references through the global window.JDATEPICKER_INSTANCES. It is a key-value dictionary, so structured:

  • the key is the jdatepicker's instance name. It's the value of the name attribute in the <input> tag, or, if that attribute was empty or not provided, the UNIX timestamp at the time the Jdatepicker was istantiated.

  • the value is the jdatepicker object.

For example, a jdatepicker with name = mydate, can be referenced through:

var mydatepicker = window.JDATEPICKER_INSTANCES["mydate"];

Options

Options for the input tag:

attribute name data type description default
disabled boolean tells if datepicker is disabled false
data-locale string lowercase two-letters ISO language code 'en'
data-format string date format, should contain a separator (like /, or -)
and the letters d (for "day"), m (for "month") and y (for "year")
y-m-d
data-mindate string the smallest available date. Must respect the format specified by data-format.
If not provided, no lower bounds are applied
null
data-maxdate string the biggest available date. Must respect the format specified by data-format.
If not provided, no upper bounds are applied
null
data-disableddates string disabled dates separated by a comma (,). Must respect the format specified by data-format.
If not provided, no dates will be disabled (Unless data-mindate and/or data-maxdate are set)
null

Keyboard shortcuts

While focus remains on datepicker component, the following keyboard shortcuts can be used:

keys description
Enter select current date and close picker
ArrowLeft current date steps one day back
ArrowRight current date steps one day forward
ArrowDown current date steps one month forward
ArrowUp current date steps one month back
PageDown current date steps one year forward
PageUp current date steps one year back

Events

Plugin provides custom events to intercept changes either in structure or in value.

event name description
jdatepicker-create let the DOM know that a INSTANCE of Jdatepicker has been created
jdatepicker-change user has changed the value (selected a date)

Languages

At the time I'm writing this document, there are only Italian (it) and English (en) available.
I don't use automatic translators. I prefer filling only languages that I know.
Other translation can be easily added in the /src/locales/locales.js file.
Remeber to use the correct ISO two-letter code. See here

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.