Giter Club home page Giter Club logo

ui-date's Introduction

ui-date directive Build Status

This directive allows you to add a date-picker to your form elements.

Alternatives

We recommend using the excellent ui-bootstrap date-picker which is maintained by a larger team.

WARNING: Support for this module may eventually be phased out as angular 2.0 arrives as there are no plans to move this to angular 2 at this time.

Requirements

  • JQuery
  • JQueryUI
  • AngularJS

Bower Usage

You may use bower for dependency management but would recommend using webpack or browserify for modules.

Install and save to bower.json by running:

bower install angular-ui-date --save

This will copy the ui-date files into your bower_components folder, along with its dependencies.

Add the css:

<link rel="stylesheet" href="bower_components/jquery-ui/themes/smoothness/jquery-ui.css"/>

Load the script files in your application:

<script type="text/javascript" src="bower_components/jquery/jquery.js"></script>
<script type="text/javascript" src="bower_components/jquery-ui/jquery-ui.js"></script>
<script type="text/javascript" src="bower_components/angular/angular.js"></script>
<script type="text/javascript" src="bower_components/angular-ui-date/dist/date.js"></script>

Add the date module as a dependency to your application module:

angular.module('MyApp', ['ui.date'])

Apply the directive to your form elements:

<input ui-date>

Options

All the jQueryUI DatePicker options can be passed through the directive including minDate, maxDate, yearRange etc.

myAppModule.controller('MyController', function($scope) {
  $scope.dateOptions = {
    changeYear: true,
    changeMonth: true,
    yearRange: '1900:-0',    
    };
});

then pass through your options:

    <input ui-date="dateOptions" name="DateOfBirth">

Static Inline Picker

If you want a static picker then simply apply the directive to a div rather than an input element.

<div ui-date="dateOptions" name="DateOfBirth"></div>

Working with ng-model

The ui-date directive plays nicely with ng-model and validation directives such as ng-required.

If you add the ng-model directive to same the element as ui-date then the picked date is automatically synchronized with the model value.

The ui-date directive stores and expects the model value to be a standard javascript Date object.

ui-date-format directive

The ui-date directive only works with Date objects. If you want to pass date strings to and from the date directive via ng-model then you must use the ui-date-format directive. This directive specifies the format of the date string that will be expected in the ng-model. The format string syntax is that defined by the JQueryUI Date picker. For example

<input ui-date ui-date-format="DD, d MM, yy" ng-model="myDate">

Now you can set myDate in the controller.

$scope.myDate = "Thursday, 11 October, 2012";

ng-required directive

If you apply the required directive to element then the form element is invalid until a date is picked.

Note: Remember that the ng-required directive must be explictly set, i.e. to "true". This is especially true on divs:

<div ui-date="dateOptions" name="DateOfBirth" ng-required="true"></div>

focusing the next element for tabbing

There is a problem with IE that re-opens the datepicker on focus(). However, this breaks tabbing. If tabbing is more important than IE for your use cases, pass in the onClose option.

myAppModule.controller('MyController', function($scope) {
  $scope.dateOptions = {
      onClose: (value, picker, $element) => {
        $element.focus()
      }
    };
});

Usage with webpack

Install with npm:

npm install --save-dev jquery jquery-ui angular angular-ui-date

Use in your app:

import angular from 'angular';
import uiDate from 'angular-ui-date';

require('jquery-ui/themes/base/minified/jquery-ui.min.css');

angular.module('MyTest', [uiDate.name])
.controller('MyCtrl', ['$scope', function($scope) {
    $scope.myDate = new Date('2015-11-17');
}]);

It is also good to ensure that jQuery is available so that angular and jquery ui can attach to it.

    webpack: {
      plugins: [
        new webpack.ProvidePlugin({
          'window.jQuery': 'jquery',
        }),
      ]
    }

another method of making jQuery recognized is to use the webpack expose-loader to expose it both as $ and jQuery

    webpack: {
      module: {
        loaders: [
                  // it helps angular to have jQuery exposed so that it uses $ instead of jqLite      
                   {
                     test: require.resolve('jquery'),
                     loader: 'expose?$!expose?jQuery',
                   },
                ]
              }
            }

Need help?

Need help using UI date?

Please do not create new issues in this repository to ask questions about using UI date

Found a bug?

Please take a look at CONTRIBUTING.md.

Contributing to the project

We are always looking for the quality contributions! Please check the CONTRIBUTING.md for the contribution guidelines.

ui-date's People

Contributors

0x-r4bbit avatar alexanderchan avatar blowsie avatar bmac avatar connorbode avatar costaraphael avatar douglasduteil avatar enriquecastl avatar flokli avatar mchapman avatar nateabele avatar petebacondarwin avatar peterdavehello avatar proloser avatar punkchameleon avatar simonv3 avatar sinelaw avatar stefanomagrassi avatar sterlingw avatar timmipetit avatar vvakame avatar waldoibarra avatar wesleycho 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  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  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

ui-date's Issues

Calendar doesn't show on page load with autofocus

I need to change field, then come back for the calendar to pop up.

<input type="text" ng-model="line.date" required ng-disabled="firstLineEntered()" placeholder="Date" id="foo" ui-date autofocus>

Adding the following line on the bottom of the page works:

<script>$(function() { $('#foo').focus(); });</script>

Using:

  • angular 1.2.0-rc.3
  • jquery 1.9.1
  • jquery-ui 1.10.3
  • ui-date master branch
  • Chromium 30.0.1599.101 (227552)

Is this a bug, or does it have something to do with the way angular works?
Wdyt?

Destroy not working

Hi I am using the datepicker in my application. I am having a memory leak issue with ui-date and after looking at the solution in the forum i have added this to my code.
element.datepicker('$destroy', function(){
element.datepicker('destroy');
});

but i can still find the detached entries in the heap snapshot.

my page doesn't contain any other elemetns except the input with ui-date.

This is how i did the testing..

load the page with only input(ui-date) element - take snapshot,

move to an empty state/ route - take snapshot- take snapshot.

I can see detached entries. But without the ui-date input i cant see those detached entries.

can someone help me in finding the solution for this!!!

I even tried this

element.datepicker('$destroy', function(){
element.datepicker('destroy');
element.off('blur');
});

ui-date and custom datepicker markup

I'm trying to use custom markup for my date picker (jsFiddle) via my own custom directive. However, the ui-date datepicker doesn't seem to be maintaining a link to the same scope. Not sure what I'm doing wrong? Any advice would be appreciated!

Model value is not updated on blur

When I set a config object with min and max date and then input an date out of the range set in the config the view is updated to the min or max date, but the model isn't updated.
Workaround would be binding a blur event updating the model:

element.bind('blur', function(){
    controller.$setViewValue(element.datepicker("getDate"));
});

Bower jquery-ui dependency shouldn't be dynamic

Since the jquery-ui dependency is defined as ">= 1.9", it breaks on build (for require.js) or runtime (for regular <script src='...'>) for applications expecting jquery-ui to be imported into a different location.

The jqeury-ui dependency should be to a specific major release, and it shouldn't automatically change whenever a new jquery-ui library is released.

Date in UTC format

If i select 07/16/2014 (16th July 2014), it gives a date value as 2014-07-15T18:30:00.000Z. When i convert this string in server side in UTC format, it gives me one day before date.

beforeShow doesn't pass through

should be something like this (just like onSelect):

var _beforeShow = opts.beforeShow || angular.noop;
opts.beforeShow = function() {
scope.$apply(function() {
showing = true;
_beforeShow();
});
};

Can't select date when minDate or maxDate changes

I have two datepickers, one is used to limit the range of the other (using a model and maxDate). When the independent one changes, I can no longer change the value of the dependent one by using the mouse. It is still possible to type a value in the dependent datepicker, but using the mouse is not possible (the value simply doesn't change).

To recreate:

  1. Create a datepicker with ng-model=endDate.
  2. Create a datepicker with maxDate: endDate (same model).
  3. Either can be changed at this time, both typing and clicking.
  4. But, when the one from step 1 is changed, the second one can't be changed anymore by using the mouse. It seems like the on-blur function is being called too often (or at the wrong time). The function is setting the value to the old value, thereby preventing the datepicker from changing at all. Typing works fine, strangely enough.

I hope this is understandable. If not, I can try to create a plnkr.

ui-date should monitor $destroy

Within the ui-date directive it should have the following:

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

An easy way to detect if this is working is to put a ui-date into a ng-repeat. Unfortunately this fix also requires a fix in the angular.js code base issue 2658 (angular/angular.js#2658).

Unknown provider: ui.dateProvider when using AngularJS 1.2.1

Error: [$injector:unpr] Unknown provider: ui.dateProvider <- ui.date
http://errors.angularjs.org/1.2.1/$injector/unpr?p0=ui.dateProvider%20%3C-%20ui.date
at http://localhost:8888/lib/angular.js:78:12
at http://localhost:8888/lib/angular.js:3451:19
at Object.getService as get
at http://localhost:8888/lib/angular.js:3456:45
at getService (http://localhost:8888/lib/angular.js:3578:39)
at invoke (http://localhost:8888/lib/angular.js:3600:13)
at Object.instantiate (http://localhost:8888/lib/angular.js:3636:23)
at http://localhost:8888/lib/angular.js:6639:28
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-route.min.js:6:476
at publicLinkFn (http://localhost:8888/lib/angular.js:5443:29)

Currently using:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-route.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-resource.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-sanitize.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

app.js:
var app = angular.module('app',[
'ngRoute',
'ngResource',
'Controllers',
'ui.date'
]);

controller.js:
Controllers.controller('MapController', ['$scope', '$http', 'ui.date', function($scope, $http) {
...
}]);

index.html:
Start Date:
End Date:

The labels and input fields load with the page but date picking doesn't work and it stops the rest of the page from loading.

Readme errata

  1. Bower components are now defined in bower.json, not component.json.
  2. Script tag paths have some errors, should be:
    <script src="components/jquery/jquery.js"></script>
    <script src="components/jquery-ui/ui/jquery.ui.datepicker.js"></script>
    <script src="components/angular/angular.js"></script>
    <script src="components/angular-ui-date/src/date.js"></script>

ui-date loses information when using dateFormat (caused due to a bug in jquery-ui)

My plunker at http://plnkr.co/edit/OM1O89Aw0wi1wDgn9ul5?p=preview demonstrates the issue. Try selecting a date NOT in the current year (i.e. if you're seeing this in 2013, try selecting a date in 2014). You'll notice that the date object in the scope -- $scope.myDate -- still has 2013 as the year.

This actually happens because of how jquery-ui responds to the dateFormat setting. However, when you're in the angular world, you'd expect the following behaviour:

  • The underlying date object should always be correct and neither dateFormat, altFormat, nor ui-date-format should affect what gets stored in it
  • The above mentioned settings should affect ONLY what is displayed to the user.

Please note, using ui-date-format does NOT solve this issue. Because that causes the ui-date to accept and emit strings into the ngModel. How does one continue to have a Date object in the ngModel while changing what is displayed to the user.

integer value should be accepted when date-format is set to @ (timestamp)

Hi,
I had to set the datepicker with a timestamp value (integer), spefifying 'ui-date-format' to '@' but it was never parsed.

Line 92

  if (angular.isString(value) ) {
            return jQuery.datepicker.parseDate(dateFormat, value);
          }
          return null;
        });

Add an 'isNumber' test ? Or parse everything and catch all exception to return null ?
Thanks.

Source missing license headers

I noticed that the JavaScript file doesn't have a license header. This seems to be a common practice amongst JavaScript libraries.

Would it be possible to add the information to the file so users can easily adhere to the project's license?

Something like:

  • Licensed under the MIT License

Thanks.

ui-date-format should accept an expression

The attribute ui-date-format should allow the use of an expression, to get the attribute dynamically from an scope variable:

app.directive('checkin', function(){ 
return {
  replace: true,
  template: "<input type="text" ng-model="$parent.date" ui-date-format="{{dateOptions.dateFormat}}" ui-options="dateOptions" ui-date>",
  link: function($scope){
    $scope.dateOptions = {
          dateFormat: 'dd/mm/yy'
          maxDate: '+1M'
          minDate: 0
          setDate: 0
          changeMonth: true
    };
  }
}

watching the uiDateFormat directive, the correct value (dd/mm/yy) is being passed to the directive, but the ui-date doesn't seem to be using it.

uiDate
    "dateOptions"

uiDateFormat
    "dd/mm/yy"

(breakpoint on line link : function (scope, element, attrs, modelCtrl){, I'm inspecting the attrs variable). The thing is, dateFormat is showing as (empty string), on line var dateFormat = attrs.uiDateFormat || uiDateFormatConfig;

datetime?

Can ui-date be configured to be a date/time picker? If so how?

minDate after date value - changes the date!

Hi,
I'm trying to use this great directive, but I'm facing a problem with the minDate option.

In a simple jQuery UI datePicker, when the minDate is after the selected date, if effect only the calendar when selecting the date.

See this example: http://jsfiddle.net/psifasim/7Ubd4/
In this example you can see that the minDate effects the datePicker when changing the date, but does not change the input value.

When using ui-date with a minDate which is after the date value - the date is being changed to the minDate - see an example with the same dates:

http://jsfiddle.net/psifasim/7Ubd4/

This prevents me from using the minDate option.

Am I using it wrong or is it a bug?

how to trigger the opening of the datepicker ?

I would like to have a button alongside the datepicker input which, when clicked, would open the datepicker dialog.

How can I do that? I was thinking about triggering the event with jQuery .click() but it's not very angular.

Fix remaining tests

Hopefully @petebacondarwin you can help me out with the last tests having to do with uiDateFormatConfig.

To run tests, do the following:

  • bower install
  • testacular start components/angular-module/test.conf.js --browsers=PhantomJS

Of course, feel free to whatever browsers you want. And yes, angular-module (for now) is that global module building toolkit you suggested we make. For now I'm trying to stick to using bower components for everything. I may drop the package if it ends up being superfluous.

Missing CSS instructions in readme.md

The instructions in the readme seem to be missing the step on adding a css link, such as:

<link rel="stylesheet" href="components/jquery-ui/themes/smoothness/jquery-ui.min.css"/>

Without it, the datepicker comes up unthemed (transparent background and unreadable mess).

Inline calander doesn't work in FireFox

Has anyone else had this issue? Just in Firefox the inline calendar isn't working.

Here's my div:

<div ui-date="dateOptions" name="selected_date" ng-model="selected_date"></div>

This is the rendered html in Firefox:

<div ng-model="selected_date" name="selected_date" ui-date="dateOptions" class="ng-pristine ng-valid"></div>

This is the rendered html in Chrome:

<div ui-date="dateOptions" name="selected_date" ng-model="selected_date" class="ng-pristine ng-valid hasDatepicker" id="dp1377248510719"><div class="ui-datepicker-inline ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" style="display: block;"><div class="ui-datepicker-header ui-widget-header ui-helper-clearfix ui-corner-all"><a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click" title="Prev"><span class="ui-icon ui-icon-circle-triangle-w">Prev</span></a><a class="ui-datepicker-next ui-corner-all" data-handler="next" data-event="click" title="Next"><span class="ui-icon ui-icon-circle-triangle-e">Next</span></a><div class="ui-datepicker-title"><select class="ui-datepicker-month" data-handler="selectMonth" data-event="change"><option value="0">Jan</option><option value="1">Feb</option><option value="2">Mar</option><option value="3">Apr</option><option value="4">May</option><option value="5">Jun</option><option value="6">Jul</option><option value="7" selected="selected">Aug</option><option value="8">Sep</option><option value="9">Oct</option><option value="10">Nov</option><option value="11">Dec</option></select>&nbsp;<span class="ui-datepicker-year">2013</span></div></div><table class="ui-datepicker-calendar"><thead><tr><th class="ui-datepicker-week-end"><span title="Sunday">Su</span></th><th><span title="Monday">Mo</span></th><th><span title="Tuesday">Tu</span></th><th><span title="Wednesday">We</span></th><th><span title="Thursday">Th</span></th><th><span title="Friday">Fr</span></th><th class="ui-datepicker-week-end"><span title="Saturday">Sa</span></th></tr></thead><tbody><tr><td class=" ui-datepicker-week-end ui-datepicker-other-month ui-datepicker-unselectable ui-state-disabled">&nbsp;</td><td class=" ui-datepicker-other-month ui-datepicker-unselectable ui-state-disabled">&nbsp;</td><td class=" ui-datepicker-other-month ui-datepicker-unselectable ui-state-disabled">&nbsp;</td><td class=" ui-datepicker-other-month ui-datepicker-unselectable ui-state-disabled">&nbsp;</td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">1</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">2</a></td><td class=" ui-datepicker-week-end " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">3</a></td></tr><tr><td class=" ui-datepicker-week-end " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">4</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">5</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">6</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">7</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">8</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">9</a></td><td class=" ui-datepicker-week-end " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">10</a></td></tr><tr><td class=" ui-datepicker-week-end " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">11</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">12</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">13</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">14</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">15</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">16</a></td><td class=" ui-datepicker-week-end " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">17</a></td></tr><tr><td class=" ui-datepicker-week-end " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">18</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">19</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">20</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">21</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">22</a></td><td class=" ui-datepicker-days-cell-over  ui-datepicker-current-day ui-datepicker-today" data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default ui-state-highlight ui-state-active" href="#">23</a></td><td class=" ui-datepicker-week-end " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">24</a></td></tr><tr><td class=" ui-datepicker-week-end " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">25</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">26</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">27</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">28</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">29</a></td><td class=" " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">30</a></td><td class=" ui-datepicker-week-end " data-handler="selectDay" data-event="click" data-month="7" data-year="2013"><a class="ui-state-default" href="#">31</a></td></tr></tbody></table></div></div>

Can't type value

It seems like it is no longer possible to type a value. I've tried without any limits (minDate/maxDate) and whenever I type into an empty input it reverts back to today's date. Then, it won't allow me to erase any of the digits. I'd expect date validation to take place on blur/enter/tab. I'm using 0.0.3 with the following default config:

app.config(['uiDateConfig', function (uiDateConfig) {
    angular.extend(uiDateConfig, {
        showWeek: true,
        dateFormat: 'yy-mm-dd',
        firstDay: 1
    });
}]);

Clean up repo

We should remove all instances of grunt from the repo as it's not really adding anything.

We should also remove jQuery as a dependency, because jQueryUI in fact adds it itself, and since THAT is where the jQuery-dependant code resides, it makes more hierarchal sense.

New release

Please make a new tag/release so we can use it with bower.
Version 0.0.3 has an error in 'main' on bower.json .It has already been fixed and commited, but no tag/release yet.
Thanks.

Demo not working

If you download the zip file and put it in your htdoc root the demo doesn't work.

Directive should convert String (or Number) to Date

Here's my problem:

  1. I'm loading my entity with angular's $http
  2. angular creates the model by using my brower's native JSON.parse function
  3. All my dates are converted to String or Number
  4. When the model change triggers the directive I get a ng-Model value must be a Date object - currently it is a ... error

My workaround:
I wrapped the uiDate-directive and copied angulars jsonStringToDate function:

dir.directive('date', function () {
    return {
        replace: true,
        templateUrl: '/claims/template/date.html',
        scope: {
            d:"=date",
            req:"=required",
            key:"@key",
            tabindex:"@tabindex",
        },
        link: function(scope, elem, attrs) {
            var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
              function jsonStringToDate(string){
                var match;
                if (match = string.match(R_ISO8601_STR)) {
                  var date = new Date(0),
                      tzHour = 0,
                      tzMin  = 0;
                  if (match[9]) {
                    tzHour = int(match[9] + match[10]);
                    tzMin = int(match[9] + match[11]);
                  }
                  date.setUTCFullYear(int(match[1]), int(match[2]) - 1, int(match[3]));
                  date.setUTCHours(int(match[4]||0) - tzHour, int(match[5]||0) - tzMin, int(match[6]||0), int(match[7]||0));
                  return date;
                }
                return string;
              }

            function int(str) {
                return parseInt(str, 10);
            }


            if (typeof scope.d === 'string'){ 
                scope.d =  jsonStringToDate(scope.d);
            }

        }
    };
});

Angular UI 2 datepickers range

I have a problem with AngularUI datepicker when i want to use 2 calendar in range each other.

When i select date in first calendar, the min date of the second calendar need to be higher than first.

So far no problem !

But, when i open the second calendar, the first date is good, but i can't click on date or can't switch month! Nothing do...

You can see demon @ http://plnkr.co/edit/4tTHEIUzVRyQJ7NOCIAs?p=preview

Thanks for help

Be more forgiving with empty strings in ng-model expressions

          // Update the date picker when the model changes
          controller.$render = function () {
              var date = controller.$viewValue;
            if ( angular.isDefined(date) && date !== null && !angular.isDate(date) ) {
              throw new Error('ng-Model value must be a Date object - currently it is a ' + typeof date + ' - use ui-date-format to convert it from a string');
            }
            element.datepicker("setDate", date);
          };

Apologies to start off with a code block. I've read that this part is intentionally strict in what it accepts (Date objects, null or undefined). However, when you define a ng-model, e.g. on an input, it defaults to empty string (""). In this case one has to define the value explicitly to null or undefined (in controller or via ng-init), otherwise it will throw the exception. Wouldn't it be reasonable to be more forgiving and treat emtpy strings like nulls in this place?

date in number format causes initial load to the ui element to fail

I encountered an issue today where I had a date(unix timestamp) which I was receiving seemed to not be binding to a datepicker created with the ui-date directive. After a bit of testing it looks like the directive does not take into account possibility of the date not being a string but rather a number in the case of ticks, or unix timestamp. I would propose in the case of the two cases mentioned above where the format of the date is potentially a number, this get handled in the formatter. See fiddle included.

http://jsfiddle.net/H4NRC/

how to toggle ui-date using a btn

I'd like to have an i.icon-calendar to toggle the date picker, what is the cleanest way to do it? is there a way to use a data-toggle attribute?

Prevent jquery datepicker formatDate exception

In my point of view, you must catch the exception in your uiDateFormat directive to prevent the dowdy console error:

TypeError: Object 123 has no method 'getFullYear'

The error occurs when you type a malformed string in the input where you apply the ui-date.

Your directive try to execute (https://github.com/angular-ui/ui-date/blob/master/src/date.js#L99):

jQuery.datepicker.formatDate(dateFormat, value);

But I think you must execute:

modelCtrl.$parsers.push(function(value){
  try{
    if (value)
      return jQuery.datepicker.formatDate(dateFormat, value);                  
  } catch(err) {}
  return null;
});

Give permission to PR

Angular 1.1.4 causes uiDatepicker to return TypeError

For those upgrading to 1.1.4

uiDatepicker throws a TypeError when switching between routed templates without a datepicker element in it. Works fine in 1.1.3, so its probably something related to angular/angular.js@fe8d893 that added feature.

Console logging right before the element.datepicker('destroy'); seems to show that the directive is called again when switching between routed templates, however, in Angular versions < 1.1.4 this behavior is not noticed. You can see http://localhost/urlhere#!/188/1/tna:755:50 is the new template that is trying to render, however this template has no datepicker methods on it.

Full error below:

TypeError: Cannot read property 'append' of undefined
    at Datepicker.$.extend._destroyDatepicker (https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js:5:135207)
    at HTMLInputElement.<anonymous> (https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js:5:163892)
    at Function.e.extend.each (https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js:2:11776)
    at e.fn.e.each (https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js:2:8304)
    at $.fn.datepicker (https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js:5:163824)
    at Object.initDateWidget (http://localhost.share/js/base/angular/angular-ui.js:304:17)
    at Object.applyFunction [as fn] (http://localhost.share/profiles#!/188/1/tna:755:50)
    at Object.e.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:89:356)
    at Object.$delegate.__proto__.$digest (http://localhost/urlhere#!/188/1/tna:820:31)
    at Object.e.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:91:431) 

update bower.json/component.json "main" property to point to the correct date.js path

Right now the "main" property in component.json and .bower.json is pointing to "./ui-date.js" file which does not exist since version 0.0.1 of the library.

{
  "name": "angular-ui-date",
  "version": "0.0.2",
  "description": "This directive allows you to add a date-picker to your form elements.",
  "author": "https://github.com/angular-ui/ui-date/graphs/contributors",
  "license": "MIT",
  "homepage": "http://angular-ui.github.com",
  "main": "./ui-date.js"
}

The correct path according to 0.0.2 and 0.0.3 project structure is ./src/ui-date.js

I'm asking for this because I'm using a grunt task to generate requirejs files based on bower installed dependencies

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.