Basic Time Input Plugin For jQuery - Fugit

Basic Time Input Plugin For jQuery - Fugit

Fugit is a small jQuery plugin that converts the standard input field into a user-friendly time selector. Your users are able to quickly select and change hours/minutes values with keyboard.

1. Install & Download the Fugit via NPM:

# Yarn
$ yarn add jquery-fugit
# NPM
$ npm install jquery-fugit --save

2. Import the jQuery Fugit into your web page.

// ES 6
import Fugit from 'jquery-fugit';
// CommonJS:
const Fugit = require('jquery-fugit');
<!-- Browser -->
<link rel="stylesheet" href="dist/jquery.fugit.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" 
        integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" 
        crossorigin="anonymous">
</script>
<script src="dist/jquery.fugit.js"></script>

3. Create a normal input field for the time selector.

<input id="fugit">

4. Call the function on the input field to initialize the time selector.

$(function() {
  $('#fugit').fugit();
});

5. The plugin provides an event which will be fired on each change.

$(function() {
  $('#fugit').fugit().on('change.fugit', function(e) {
    console.log('value changed to', $(e.currentTarget).val());
  });
});

This awesome jQuery plugin is developed by timgthomas. For more Advanced Usages, please check the demo page or visit the official website.

  • Publication date: 23.01.2018
  • Source