fng-bootstrap-date 0.12.0-beta.192 → 0.12.0-beta.194
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.
- package/fng-bootstrap-date.js +54 -40
- package/package.json +1 -1
package/fng-bootstrap-date.js
CHANGED
|
@@ -12,13 +12,14 @@
|
|
|
12
12
|
$scope.popup.opened = true;
|
|
13
13
|
}
|
|
14
14
|
}])
|
|
15
|
-
.directive('fngUiBootstrapDatePicker', ['$compile', '$
|
|
16
|
-
function ($compile, $
|
|
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
|
|
35
|
-
var
|
|
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
|
-
|
|
41
|
-
var
|
|
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 (
|
|
48
|
-
jsonDateOptions = JSON.parse(
|
|
48
|
+
if (processedAttrs.directiveOptions['date-options']) {
|
|
49
|
+
jsonDateOptions = JSON.parse(processedAttrs.directiveOptions['date-options'].replace(/'/g, '"'));
|
|
49
50
|
}
|
|
50
|
-
scope.dateOptions = Object.assign(
|
|
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 =
|
|
58
|
-
template = pluginHelper.buildInputMarkup(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
scope
|
|
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
|
-
|
|
95
|
+
return formMarkupHelper.generateSimpleInput(
|
|
96
|
+
str,
|
|
97
|
+
processedAttrs.info,
|
|
98
|
+
processedAttrs.options
|
|
99
|
+
);
|
|
82
100
|
}
|
|
83
|
-
|
|
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
|
-
//
|
|
120
|
-
|
|
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