fng-bootstrap-date 0.12.0-beta.191 → 0.12.0-beta.193

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,13 +12,14 @@
12
12
  $scope.popup.opened = true;
13
13
  }
14
14
  }])
15
- .directive('fngUiBootstrapDatePicker', ['$compile', '$filter', '$timeout', 'pluginHelper', 'formMarkupHelper', 'cssFrameworkService',
16
- function ($compile, $filter, $timeout, pluginHelper, formMarkupHelper) {
15
+ .directive('fngUiBootstrapDatePicker', ['$compile', '$timeout', 'pluginHelper', 'formMarkupHelper', 'cssFrameworkService',
16
+ function ($compile, $timeout, pluginHelper, formMarkupHelper) {
17
17
  return {
18
18
  restrict: 'E',
19
19
  replace: true,
20
20
  priority: 1,
21
21
  controller: 'FngUIBootstrapDateCtrl',
22
+ scope: true, // our own scope, but not isolated - prevents multiple instances on the same page from opening each other
22
23
  link: function (scope, element, attrs) {
23
24
  function afterTimeout() {
24
25
  $timeout(function() {
@@ -31,61 +32,73 @@
31
32
  }
32
33
 
33
34
  var template;
34
- var processedAttr = pluginHelper.extractFromAttr(attrs, 'fngUiBootstrapDatePicker');
35
- var overRiddenDefaults = {
35
+ var processedAttrs = pluginHelper.extractFromAttr(attrs, 'fngUiBootstrapDatePicker');
36
+ var overriddenDefaults = {
36
37
  'show-button-bar': false,
37
38
  'show-meridian': false,
38
39
  'date-format': 'dd/MM/yyyy'
39
40
  };
40
- overRiddenDefaults = Object.assign({}, overRiddenDefaults, processedAttr.directiveOptions);
41
- var overRiddenDateDefaults = {
41
+ overriddenDefaults = Object.assign({}, overriddenDefaults, processedAttrs.directiveOptions);
42
+ var overriddenDateDefaults = {
42
43
  showWeeks: false
43
44
  };
44
45
  var jsonDateOptions = {
45
46
  'showWeeks': false
46
47
  };
47
- if (processedAttr.directiveOptions['date-options']) {
48
- jsonDateOptions = JSON.parse(processedAttr.directiveOptions['date-options'].replace(/'/g, '"'));
48
+ if (processedAttrs.directiveOptions['date-options']) {
49
+ jsonDateOptions = JSON.parse(processedAttrs.directiveOptions['date-options'].replace(/'/g, '"'));
49
50
  }
50
- scope.dateOptions = Object.assign(overRiddenDateDefaults, jsonDateOptions);
51
+ scope.dateOptions = Object.assign(overriddenDateDefaults, jsonDateOptions);
51
52
  ["minDate","maxDate"].forEach(v => {
52
53
  if (scope.dateOptions[v] && typeof scope.dateOptions[v] === "string") {
53
54
  scope.dateOptions[v] = new Date(scope.dateOptions[v]);
54
55
  }
55
56
  })
56
57
 
57
- const isArray = processedAttr.info.array;
58
- template = pluginHelper.buildInputMarkup(scope, attrs.model, processedAttr.info, processedAttr.options, isArray, isArray, function (buildingBlocks) {
59
- var str = '';
60
- for (var opt in overRiddenDefaults) {
61
- if (opt !== 'date-options') {
62
- str += ' ' + opt + '="' + overRiddenDefaults[opt] + '"';
58
+ const isArray = processedAttrs.info.array;
59
+ template = pluginHelper.buildInputMarkup(
60
+ scope,
61
+ attrs,
62
+ {
63
+ processedAttrs,
64
+ addButtons: isArray,
65
+ needsX: isArray,
66
+ },
67
+ function (buildingBlocks) {
68
+ var str = buildingBlocks.common.trim();
69
+ for (var opt in overriddenDefaults) {
70
+ if (opt !== 'date-options') {
71
+ str += ` ${opt}="${overriddenDefaults[opt]}"`;
72
+ }
63
73
  }
64
- }
65
- if (processedAttr.info.title) {
66
- str += ' title="' + processedAttr.info.title + '"';
67
- }
68
- if (processedAttr.info.arialabel) {
69
- str += ' aria-label="' + processedAttr.info.arialabel + '"';
70
- }
71
- const prefix = "uibDatePopup";
72
- const random = Math.floor(Math.random() * 10000);
73
- scope[prefix + random] = {
74
- opened: {}
75
- };
76
- scope["open" + random] = function ($index) {
77
- const all = Object.keys(scope).filter((k) => k.startsWith(prefix));
78
- for (const key of all) {
79
- scope[key].opened = {};
74
+ if (processedAttrs.info.title) {
75
+ str += ` title="${processedAttrs.info.title}"`;
76
+ }
77
+ if (processedAttrs.info.arialabel) {
78
+ str += ` aria-label="${processedAttrs.info.arialabel}"`;
79
+ }
80
+ if (processedAttrs.info.required) {
81
+ str += " required";
82
+ }
83
+ const markup = formMarkupHelper.addTextInputMarkup(buildingBlocks, processedAttrs.info, '');
84
+ const disabled = pluginHelper.genDisabledStr(scope, processedAttrs, "");
85
+ const dateFormat = processedAttrs.directiveOptions.format || processedAttrs.directiveOptions['date-format'] || 'dd/MM/yy';
86
+ str += ` ${markup}${disabled}datepicker-options="dateOptions" uib-datepicker-popup="${dateFormat}"`;
87
+
88
+ if (disabled?.trim().toLowerCase() !== "disabled") {
89
+ scope.popup = { opened: false };
90
+ scope.open = function () {
91
+ scope.popup.opened = true;
92
+ }
93
+ str += ' is-open="popup.opened" ng-click="open()" validdate '; // don't remove the trailing space here
80
94
  }
81
- scope[prefix + random].opened[$index || 0] = true;
95
+ return formMarkupHelper.generateSimpleInput(
96
+ str,
97
+ processedAttrs.info,
98
+ processedAttrs.options
99
+ );
82
100
  }
83
- return formMarkupHelper.generateSimpleInput(
84
- buildingBlocks.common + str + ' validdate datepicker-options="dateOptions" uib-datepicker-popup="' + (processedAttr.directiveOptions.format || processedAttr.directiveOptions['date-format'] || 'dd/MM/yy') + '" is-open="' + prefix + random + '.opened[$index || 0]" ng-click="open' + random + '($index)" ' + formMarkupHelper.addTextInputMarkup(buildingBlocks, processedAttr.info, ''),
85
- processedAttr.info,
86
- processedAttr.options
87
- );
88
- });
101
+ );
89
102
  var html = $compile(template)(scope);
90
103
  if (element[0].parentElement) {
91
104
  element.replaceWith(html);
@@ -116,8 +129,9 @@
116
129
 
117
130
  ctrl.$validators.validdate = function(modelValue, viewValue) {
118
131
  if (ctrl.$isEmpty(modelValue)) {
119
- // consider empty models to be invalid
120
- return false;
132
+ // if empty should be considered invalid, the field should be set to required (which will
133
+ // then be validated elsewhere)
134
+ return true;
121
135
  }
122
136
  var retVal = true;
123
137
  if (minDate || maxDate) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fng-bootstrap-date",
3
- "version": "0.12.0-beta.191",
3
+ "version": "0.12.0-beta.193",
4
4
  "description": "Date input plugin for forms-angular, using the Bootstrap datepicker from Angular-ui-bootstrap",
5
5
  "main": "fng-bootstrap-date.js",
6
6
  "scripts": {