Giter VIP home page Giter VIP logo

meteor-autoform-datetimepicker's Introduction

notorii:autoform-datetimepicker

An add-on Meteor package for aldeed:autoform. Provides a single custom input type, "datetimepicker", which renders an input that allows selecting datetime (or just date) across ALL platforms (mobile, desktop, wrapped inside a Cordova / Phonegap app). Specifically:

  • Mobile (Android, iOS) (either Cordova wrapped apps or mobile web browser) just use the datetime-local (or date) input type, which will bring up the native date(time) input on mobile.
  • Desktop web interfaces use Pikaday datetimepicker functionality.

Default datetime-local and date input types handle the majority of cases so this basically just does 3 things:

  1. adds Pikaday functionality for desktop web
  2. allows custom date/datetime formats (the transformation to make it "just work" with datetime-local formats will be handled for you)
  3. provides ONE cross platform input type that will handle all cases

Why?

  • the default datetime-local and date input types do not have datepickers for desktop web
  • other date(time)pickers such as bs-datetimepicker require other dependencies such as bootstrap or jQuery and do not work (as well) on mobile / when wrapped as a Cordova app, requiring custom code to switch out the datetime picker pending the platform - this package handles that all for you so you just set ONE input type and it works everywhere (across all platforms - web, Android, iOS).

Demo

Demo

Source

Dependencies

  • aldeed:autoform
  • pikaday-time - Pikaday Owenmead time picker fork (recommended to use bower with mquandalle:bower package to install, which will auto-include the necessary pikaday.js and pikaday.css files)
  • momentjs:moment

Installation

In a Meteor app directory:

meteor add notorii:autoform-datetimepicker

Add Pikaday javascript and css files, e.g.: add "pikaday-time": "latest" to your bower.json file.

Usage

Specify "datetimepicker" for the type attribute of any input and set teh SimpleSchema to be an object:

{{> afQuickField name="dueDate" type="datetimepicker" opts=optsDatetimepicker}}

In the schema, which will then work with a quickForm or afQuickFields:

AFDatetimepickerSchema =new SimpleSchema({
  dueDate: {
    type: String,
    optional: true
  }
});

Specify options, including Pikaday options, with a template helper.

  • @param {String} [formatValue ='YYYY-MM-DD HH:mm:ssZ'] The input and output value format (NOT what is displayed to the user by the Pikaday date time picker per se)

  • @param {Object} [pikaday] The normal Pikaday date/time picker options, see: https://github.com/dbushell/Pikaday#configuration AND https://github.com/owenmead/Pikaday for time picker options, which are enabled by default

    • @param {String} [format ='YYYY-MM-DD h:mmA'] The Pikaday / input value format that is displayed. NOTE: the display value will only match what is set here for Pikaday (web desktop); mobile uses the native format for the date/time picker of that platform.

To disable the time picker and just have a date select, change the formatValue option (and pikaday.format generally as well) to specify the format you want (if no 'h' and no 'H' in the formatValue, it will assume date only) and then set the pikaday.showTime option to false.

if(Meteor.isClient) {
  Template.autoformDatetimepickerBasic.helpers({
    optsDatetimepicker: function() {
      return {
        //WHAT IS STORED (i.e in the database)
        // formatValue: 'YYYY-MM-DD'
        pikaday: {
          //what is DISPLAYED (to the user)
          // format: 'MMM D, YYYY',
          // showTime: false,
        }
      }
    }
  });
}

meteor-autoform-datetimepicker's People

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.