From 709ef87d1983613f94f2ae5bffb23ba0eedcfcdc Mon Sep 17 00:00:00 2001 From: Francois Zaninotto Date: Wed, 9 Mar 2016 12:14:55 +0100 Subject: [PATCH 1/3] Fix Datepicker JS error Closes #961 --- src/javascripts/ng-admin/Crud/CrudModule.js | 1 - .../ng-admin/Crud/field/datepickerPopup.js | 27 ------------------- .../ng-admin/Crud/field/maDateField.js | 2 +- 3 files changed, 1 insertion(+), 29 deletions(-) delete mode 100644 src/javascripts/ng-admin/Crud/field/datepickerPopup.js diff --git a/src/javascripts/ng-admin/Crud/CrudModule.js b/src/javascripts/ng-admin/Crud/CrudModule.js index cfe0e320..c4c666b1 100644 --- a/src/javascripts/ng-admin/Crud/CrudModule.js +++ b/src/javascripts/ng-admin/Crud/CrudModule.js @@ -21,7 +21,6 @@ CrudModule.service('RestWrapper', require('./misc/RestWrapper')); CrudModule.directive('maJsonValidator', require('./validator/maJsonValidator')); -CrudModule.directive('uibDatepickerPopup', require('./field/datepickerPopup')); CrudModule.directive('maField', require('./field/maField')); CrudModule.directive('maButtonField', require('./field/maButtonField')); CrudModule.directive('maChoiceField', require('./field/maChoiceField')); diff --git a/src/javascripts/ng-admin/Crud/field/datepickerPopup.js b/src/javascripts/ng-admin/Crud/field/datepickerPopup.js deleted file mode 100644 index cfc5327c..00000000 --- a/src/javascripts/ng-admin/Crud/field/datepickerPopup.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Fixes an issue with Bootstrap Date Picker - * @see https://github.com/angular-ui/bootstrap/issues/2659 - * @see https://github.com/angular-ui/bootstrap/pull/4062 - * - * How does it work? AngularJS allows multiple directives with the same name, - * and each is treated independently though they are instantiated based on the - * same element/attribute/comment. - * - * So this directive goes along with ui.bootstrap's uib-datepicker-popup directive. - * @see http://angular-ui.github.io/bootstrap/versioned-docs/0.12.0/#/datepicker - */ -export default function datepickerPopup() { - return { - restrict: 'EAC', - require: 'ngModel', - link: function(scope, element, attr, controller) { - // 'new Date' fallback - scope.value = scope.value instanceof Date ? scope.value:new Date(scope.value); - - //remove the default formatter from the input directive to prevent conflict - controller.$formatters.shift(); - } - }; -} - -datepickerPopup.$inject = []; diff --git a/src/javascripts/ng-admin/Crud/field/maDateField.js b/src/javascripts/ng-admin/Crud/field/maDateField.js index 23ee715b..46650433 100644 --- a/src/javascripts/ng-admin/Crud/field/maDateField.js +++ b/src/javascripts/ng-admin/Crud/field/maDateField.js @@ -13,7 +13,7 @@ export default function maDateField() { link: function(scope, element) { var field = scope.field(); scope.name = field.name(); - scope.rawValue = scope.value; + scope.rawValue = scope.value === null ? new Date() : (scope.value instanceof Date ? scope.value : new Date(scope.value)); scope.$watch('rawValue', function(rawValue) { scope.value = field.parse()(rawValue); }); From 1d037932d264473f158a998ced1b1ab554ec350b Mon Sep 17 00:00:00 2001 From: Francois Zaninotto Date: Fri, 11 Mar 2016 10:31:00 +0100 Subject: [PATCH 2/3] Fix test --- src/javascripts/test/unit/Crud/field/maDateFieldSpec.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/javascripts/test/unit/Crud/field/maDateFieldSpec.js b/src/javascripts/test/unit/Crud/field/maDateFieldSpec.js index 670eb688..c17367e6 100644 --- a/src/javascripts/test/unit/Crud/field/maDateFieldSpec.js +++ b/src/javascripts/test/unit/Crud/field/maDateFieldSpec.js @@ -3,12 +3,10 @@ describe('directive: date-field', function() { 'use strict'; var dateDirective = require('../../../../ng-admin/Crud/field/maDateField'); - var datepickerPopupDirective = require('../../../../ng-admin/Crud/field/datepickerPopup'); var DateField = require('admin-config/lib/Field/DateField'); angular.module('testapp_DateField', ['ui.bootstrap', 'ui.bootstrap.tpls']) - .directive('maDateField', dateDirective) - .directive('datepickerPopup', datepickerPopupDirective); + .directive('maDateField', dateDirective); var $compile, scope, From 88e9493fd1317c7ae8dd28356b47d4d328b452b3 Mon Sep 17 00:00:00 2001 From: Francois Zaninotto Date: Fri, 18 Mar 2016 22:17:59 +0100 Subject: [PATCH 3/3] Fix test in PhantomJS (already passes in Chrome) --- src/javascripts/ng-admin/Crud/field/maDateField.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/javascripts/ng-admin/Crud/field/maDateField.js b/src/javascripts/ng-admin/Crud/field/maDateField.js index 46650433..f5e84768 100644 --- a/src/javascripts/ng-admin/Crud/field/maDateField.js +++ b/src/javascripts/ng-admin/Crud/field/maDateField.js @@ -13,7 +13,7 @@ export default function maDateField() { link: function(scope, element) { var field = scope.field(); scope.name = field.name(); - scope.rawValue = scope.value === null ? new Date() : (scope.value instanceof Date ? scope.value : new Date(scope.value)); + scope.rawValue = scope.value == null ? new Date() : (scope.value instanceof Date ? scope.value : new Date(scope.value)); scope.$watch('rawValue', function(rawValue) { scope.value = field.parse()(rawValue); });