Giter Club home page Giter Club logo

pikaday-angular's Introduction

pikaday-angular v2.0.0

pikaday-angular is a directive wraper that aims to make using Pikaday with AngularJS as simple as possible. Examples →

WARNING! This lib was made for a very old version of Angular.JS (v1.3.15) and, unfortunately, I no longer have time to maintain it.

How simple? - Include the module as a dependency.

angular.module('YourApp', ['pikaday'])

Then use the pikaday attribute to bind the picker to a scope.

<input pikaday="myPickerObject">

You now have access to Pikaday's methods from the scoped object myPickerObject.

Attributes

Any of Pikaday's options can be passed to the corresponding attribute, the directive takes care of coercing the value to the proper type.*

*With the exception of function expressions, which are bound as callbacks. see: Functions

<input pikaday="myPickerObject" number-of-months="2">

Global config

Optionally, you may provide a global config* object for all pickers by creating a pikadayConfigProvider.

*In-line attributes override global configs.

angular.module('YourApp')
  .config(['pikadayConfigProvider', function(pikaday) {
    pikaday.setConfig({
      numberOfMonths: 2
    });
  }])

Functions

Pikaday has several events you can bind callbacks to: onSelect, onOpen, onClose, onDraw, and disableDayFn. Callbacks can be passed two optional, predefined parameters in the function expression:

Option Type Description
pikaday Object: Pikaday The Pikaday object for the current input
date Object: Date The current selected date, or date to be evaluated by the filter

Example:

<!-- controller as syntax - onSelect callback -->
<input pikaday="ctrl.myPicker" on-select="ctrl.onPikadaySelect(pikaday)">

<!-- scope syntax - passing date to filter Fn -->
<input pikaday="myPicker" on-disable-day="myDateFilter(date)">

Then in your controller:

angular.module('YourApp')
  .controller('sampleController', function() {
    // use scope.onPikadaySelect for older scope syntax
    this.onPikadaySelect = function onPikadaySelect(pikaday) {
      alert(pikaday.toString());
    };
  });

Methods

You can access any of Pikaday's methods though the named scope, i.e. myPickerObject. For example, if you needed to apply a maximum date after the picker is initialised, you simply call the setMaxDate method.

angular.module('YourApp')
  .controller('sampleController', function() {
    this.someFunction = function () {
      this.myPickerObject.setMaxDate(new Date( '01/01/2016' ));
    }
  });

See Pikaday's documentation for a full list of available methods.

i18n

To set the language with the i18n attribute, you must create a locales object, and pass it to setConfig. This makes setting locale using the attribute i18n="de" possible. You may also want to configure Moment.js to handle formatting the output in the appropriate i18n locale. see: Moment.

.config(['pikadayConfigProvider', function(pikaday) {

  var locales = {
    de: {
      previousMonth : 'Vorheriger Monat',
      nextMonth     : 'Nächster Monat',
      months        : ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
      weekdays      : ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
      weekdaysShort : ["So.", "Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa."]
    }
  };

  pikaday.setConfig({

    i18n: locales.de, // sets the default language [optional]
    locales: locales // required if setting the language using the i18n attribute

  });
}])

Moment.js

If you load Moment.js anywhere in your HTML, Pikaday will automatically start using Moment to parse input dates and format the pickers output. If you are using Moment.js anywhere in your document, you should* specify the format option, either in the global config or as an attribute.

*Otherwise Moment.js will use some rather counter intuitive ISO8601 compliant defaults "YYYY-MM-DDTHH:mm:ssZ".

Caveat: Whilst it's possible to specify some fancy output formats with Moment, it may have a detrimental effect on the users ability to enter a date in the input field, as Moment.js will expect the input to conform to the current format setting. See Moment's docs for clarification of some of the issues regarding date string parsing.

To get Moment.js to handle i18n output formatting, you need to load the appropriate Moment.js locale file. Moment will automatically default to the most recently loaded locale file. Explicit locale selection can be made programmatically by calling moment.locale("<key>") with the key of a loaded locale.

NPM & Bower

[npm || bower] install --save pikaday-angular

pikaday-angular is provided in a UMD wrapper, making it compatible with several build systems & preprocessors such as Browserify, see the source of the Example page to see pikaday-angular being used with Browserify & Gulp.

Testing

The coercion tests can be run after installing the required npm packages.

# From the command line:
$ npm install
$ npm test

Changelog

v2.0.0: WARNING: BREAKING CHANGES

This version represents a complete rewrite of the directive with the goal of having complete support for all of Pikaday's options, both in the provider and as attributes, whilst being more maintainable in the long run. The directive no longer applies it's own defaults, instead decorating the config object only when needed. The new build should be flexible, but still simple to use.

  • Clarified naming of module and provider :
  • Updated to support all of Pikaday config options, functions and callbacks
  • Any option can now be added via pikadayConfigProvider
  • Added coercion tests npm install; npm test
  • Removed all defaults (directive will only apply attributes that are present)
  • Added multiple locale selection
  • Updated README.md

pikaday-angular's People

Contributors

lfdm avatar nverba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pikaday-angular's Issues

Conflict with other directives

Hi, there. I discovered the conflict of your plugin with another.
I'm using ui-mask in my project to set the masked input of my date in format 'DD.MM.YYYY' and using a trigger to open pickaday calendar.

Markup:

<input 
    ui-mask 
    clear-errors 
    model-view-value="true" 
    ui-mask-placeholder-char="-" 
    ng-attr-ui-mask="99.99.9999" 
    ng-model="$ctrl.registerData.securityQuestionDate" 
    format="DD.MM.YYYY" 
    pikaday="$ctrl.registerData.pickerObject" 
    type="text" 
    class="form-control" 
    id="registerSecurityQuestion" 
    placeholder="DD.MM.YYYY" 
    trigger="datepicker-button">
<div 
    id="datepicker-button" 
    ng-click="$ctrl.focusInput('registerSecurityQuestion')" 
    class="input-group-addon input-group-addon_button">
    <span class="icon icon_calendar"></span>
</div>

When I select the date calendar doesn't hide.
Only after second click.

How can I handle that event?

A "pikaday-options" parameter for sending all options without using attributes

Hi,

It would be great that user of this directive can send a configuration object to the directive without using element attributes. This object can act similar to default "pikadayConfig" configuration object and it can be applied after the default provider configuration and before applying attribute parameters.

My use case is: I have a custom wrapper directive (for example: "my-app-calendar", isolated scope) that act as a container for "pikaday" element for application specific purposes (changing routes for calendar or doing other calendar related-app specific things). I don't want to define all possible "pikaday" parameters on this directive and delegate them to real "pikaday" directive with attributes.

Clear model data

Great little directive, but I'm having trouble clearing the date field (I'll admit, I've been away from Angular for a bit, but thought this would be easy).

<input pikaday="filterCtrl.filter.fromDate" on-select="filterCtrl.selectDate(pikaday,'fromDate')" />

I thought pikaday would clear if I set filterCtrl.filter.fromDate = null but the text is still in the input field.

I don't see anywhere in your code to clear. Is this possible? Or do I need to just go get the element and clear it?

destroy pikaday on scope destruction

could you please add the following, so that one doesn't just add and add pikaday divs at the bottom of the page

scope.$on('$destroy', function () {
  picker.destroy();
});

Sending off Pikaday object through REST

Hey,

I am trying to submit my data through REST and this includes a Pikaday object.
Following is the error:

TypeError: Converting circular structure to JSON
at Object.stringify (native)

I partially manage to get around by using .getString(), but then I need to check if there is an object (because the function does not work on undefined, in case the date is optional).

Probably something I am overlooking, any suggestion is appreciated!

Bower?

Are you open to having this available for download via bower?

Locale with moment

Hey!

Thanks for a great directive!
Trying to get locale working here. After going through the docs, it seems that moment.js loads the English locale by default.
I have moment.js included in my app, but the date formats that got output are still YYYY-MM-DD. Assuming that these are not the default English locales, how can I get this to work?

Thanks!

Issue with typing directly into the Pikaday input

Hi, first of all thank you for the directive.

I'm having issues with how the date is formatted after the user type directly into the input. This is also not working correctly on your demo page.

For example:
'01/02/2015' gets formatted to '01 January 0002'
'01 02 2014' and '01 05 2014' both gets formatted to '01 January 2014'

I was hoping to use ngBlur to capture the date before the directive tries to format it, but I can only capture the formatted version.

So now I can only use ngChange to capture all the changes and format it manually on ngBlur.

If you could please fix this issue that would be most helpful!

dynamic id for container

it doesn't find the element if I use a dynamic id for the container:

example:
pika attr:
container="option{{ $index }}Container"
container attr:
id="option{{ $index }}Container"

WARNING: Tried to load angular more than once.

Solved removing require('angular')

module.exports = factory(require('angular'), require('pikaday'));

to

module.exports = factory(require('pikaday'));

apply changes for all UMD exports


and changing factory params

function (angular, Pikaday) { ... }

to

function (Pikaday) { ... }

Unable to use custom format to be displayed with pikaday

Hi,

First of all, Thank you for your great work.

I have a problem setting a date (string) on a pikaday directive : in fact, i think the problem is a problem a format config. I tried to set in the config but it seems it doesn't work.

My format is 'DD/MM/YYYY' when i use these attributes : default-date="17/01/2007" set-default-date="true" it doesn't work, but when i use default-date="12/01/2007" it shows the correct value but with the wrong format "Sat Dec 01 2007" .

Here is a plunker exposing the problem http://plnkr.co/edit/AVePt7?p=preview .

Thanks in advance.

[enhancement] appendTo or custom classes per instance

Hi,

Very good directive.. however I ran into a limitation that is design oriented.
So in a few cases I need to style my pikaday differently and since the pikaday is appended at the same place right before the body, I have little to no control for use-cases like these. Would be nice to be able to give the pika-single a class depending on the instance for example, or to be able to choose where to append it.

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.