nice-elements 1.15.0 → 1.15.1
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/.claude/launch.json +11 -0
- package/CHANGELOG.md +10 -0
- package/README.md +1 -1
- package/bower.json +1 -1
- package/dist/nice.js +118 -30
- package/dist/nice.min.js +1 -1
- package/dist/style.css +18 -10
- package/dist/style.css.map +1 -1
- package/dist/style.min.css +2 -2
- package/package.json +1 -1
- package/src/components/nice-calendar/nice-calendar.html +4 -0
- package/src/components/nice-checkbox/nice-checkbox.html +10 -4
- package/src/components/nice-checkbox/nice-checkbox.js +1 -0
- package/src/components/nice-checkbox/nice-checkbox.scss +7 -0
- package/src/components/nice-choice/nice-choice.js +11 -0
- package/src/components/nice-date/nice-date.html +10 -1
- package/src/components/nice-date/nice-date.js +47 -0
- package/src/components/nice-date/nice-date.scss +1 -0
- package/src/components/nice-date-input/nice-date-input.js +1 -1
- package/src/components/nice-date-range/nice-date-range.html +1 -1
- package/src/components/nice-datetime-picker/nice-datetime-picker.html +3 -0
- package/src/components/nice-dropdown/nice-dropdown.js +12 -3
- package/src/components/nice-dropdown/nice-dropdown.scss +0 -11
- package/src/components/nice-percent/nice-percent.js +10 -3
- package/src/components/nice-search/nice-search.js +8 -14
- package/src/components/nice-search2/nice-search2.html +1 -1
- package/src/components/nice-search2/nice-search2.js +1 -0
- package/src/components/nice-toggle/nice-toggle.html +3 -0
- package/src/components/nice-upload/nice-upload.html +1 -1
- package/src/components/nice-yesno/nice-yesno.html +3 -0
- package/src/services/nice-service.js +1 -1
- package/src/styles/_nice-common.scss +17 -0
package/package.json
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
<div class="nice-field col-xs-12" ng-class="[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]">
|
|
8
8
|
<div class="disabled-shield" ng-if="isDisabled"></div>
|
|
9
9
|
|
|
10
|
+
<!-- Only for form validation (start and end date have to be set when required) -->
|
|
11
|
+
<input class="hidden-input" ng-model="startDate" ng-required="required" tabindex="-1" />
|
|
12
|
+
<input class="hidden-input" ng-model="endDate" ng-required="required" tabindex="-1" />
|
|
13
|
+
|
|
10
14
|
<div class="nice-calendar-wrapper">
|
|
11
15
|
<div class="nice-calendar-weeks">
|
|
12
16
|
<div class="nice-calendar-header">
|
|
@@ -9,10 +9,16 @@
|
|
|
9
9
|
}"
|
|
10
10
|
ng-click="toggle()"
|
|
11
11
|
>
|
|
12
|
-
<
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
<span class="nice-checkbox-box">
|
|
13
|
+
<button type="button" class="btn nice-checkbox-checkbox" ng-disabled="isDisabled">
|
|
14
|
+
<nice-icon ng-if="model" class="nice-checkbox-check" icon="icon-check"></nice-icon>
|
|
15
|
+
<nice-icon ng-if="!model && indeterminate" class="nice-checkbox-check" icon="icon-minus"></nice-icon>
|
|
16
|
+
</button>
|
|
17
|
+
|
|
18
|
+
<!-- Only for form validation (checkbox must be checked when required).
|
|
19
|
+
Placed next to the box so the browser "required" bubble points at it. -->
|
|
20
|
+
<input type="checkbox" class="hidden-input" ng-model="model" ng-required="required" tabindex="-1" />
|
|
21
|
+
</span>
|
|
16
22
|
<div class="nice-checkbox-info" ng-transclude>
|
|
17
23
|
<nice-title text="title || niceTitle" help="help" required="required" description="niceDescription" label-width="col-xs-12"></nice-title>
|
|
18
24
|
<!-- <div ng-if="title || niceTitle" class="nice-checkbox-message" ng-class="{ 'nice-disabled': isDisabled }">{{ title || niceTitle }}</div> -->
|
|
@@ -29,6 +29,7 @@ angular.module('niceElements')
|
|
|
29
29
|
multiple: '=?',
|
|
30
30
|
help: '@',
|
|
31
31
|
isInline: '=?',
|
|
32
|
+
required: '=?',
|
|
32
33
|
onChange: '&?'
|
|
33
34
|
},
|
|
34
35
|
controller: function ($attrs, $scope) {
|
|
@@ -208,6 +209,16 @@ angular.module('niceElements')
|
|
|
208
209
|
}
|
|
209
210
|
});
|
|
210
211
|
|
|
212
|
+
// Required: something has to be selected (at least one item when multiple)
|
|
213
|
+
const checkRequired = function () {
|
|
214
|
+
if (!$scope.formChoice) return;
|
|
215
|
+
let hasValue = $scope.model !== null && angular.isDefined($scope.model);
|
|
216
|
+
if ($scope.multiple) hasValue = !!($scope.model && $scope.model.length);
|
|
217
|
+
$scope.formChoice.$setValidity('required', !$scope.required || hasValue);
|
|
218
|
+
};
|
|
219
|
+
$scope.$watchCollection('model', checkRequired);
|
|
220
|
+
$scope.$watch('required', checkRequired);
|
|
221
|
+
|
|
211
222
|
}
|
|
212
223
|
};
|
|
213
224
|
});
|
|
@@ -11,7 +11,16 @@
|
|
|
11
11
|
|
|
12
12
|
<!------------------------------ Input ------------------------------>
|
|
13
13
|
<div class="nice-date-button input-group" ng-class="{ 'open': isOpen }" ng-show="!inline" ng-click="toggleOpen()">
|
|
14
|
-
<input
|
|
14
|
+
<input
|
|
15
|
+
type="text"
|
|
16
|
+
class="form-control"
|
|
17
|
+
ng-model="innerDate.value"
|
|
18
|
+
placeholder="{{ placeholder }}"
|
|
19
|
+
ng-required="required"
|
|
20
|
+
ng-disabled="isDisabled"
|
|
21
|
+
ng-blur="parseTypedDate()"
|
|
22
|
+
ng-keydown="typedDateKeydown($event)"
|
|
23
|
+
/>
|
|
15
24
|
<span class="input-group-btn">
|
|
16
25
|
<button type="button" class="btn btn-default btn-right" ng-disabled="isDisabled" ng-if="!(model && nullable)">
|
|
17
26
|
<nice-icon icon="icon-calendar"></nice-icon>
|
|
@@ -160,6 +160,53 @@ angular.module('niceElements')
|
|
|
160
160
|
};
|
|
161
161
|
|
|
162
162
|
|
|
163
|
+
// ------------------ Typed date ------------------
|
|
164
|
+
// Formats accepted when the date is typed in (strict parsing)
|
|
165
|
+
const TYPED_DATE_FORMATS = ['D.M.YYYY', 'D.M.YY', 'D.M.', 'D.M'];
|
|
166
|
+
const TYPED_TIME_FORMATS = ['D.M.YYYY H:mm', 'D.M.YY H:mm', 'D.M. H:mm', 'D.M H:mm'];
|
|
167
|
+
|
|
168
|
+
// Parse typed text on blur (or Enter). Invalid or out of range text reverts to the current model.
|
|
169
|
+
$scope.parseTypedDate = function () {
|
|
170
|
+
const text = ($scope.innerDate.value || "").replace("•", " ").replace(/\s+/g, " ").trim();
|
|
171
|
+
|
|
172
|
+
// Nothing changed
|
|
173
|
+
if (text == $scope.formatDate($scope.model).replace("•", " ").replace(/\s+/g, " ")) return;
|
|
174
|
+
|
|
175
|
+
// Empty text clears the model, unless the field can't be empty
|
|
176
|
+
if (!text) {
|
|
177
|
+
if ($scope.nullable || $scope.required) $scope.setTypedDate(null);
|
|
178
|
+
else $scope.innerDate.value = $scope.formatDate($scope.model);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const formats = $scope.time ? TYPED_TIME_FORMATS.concat(TYPED_DATE_FORMATS) : TYPED_DATE_FORMATS;
|
|
183
|
+
const date = moment(text, formats, true);
|
|
184
|
+
if (!date.isValid() || _isDisabledDate(date)) {
|
|
185
|
+
$scope.innerDate.value = $scope.formatDate($scope.model);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (!$scope.time) $scope._removeTime(date);
|
|
190
|
+
$scope.setTypedDate(date);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
$scope.setTypedDate = function (date) {
|
|
194
|
+
$scope.model = date;
|
|
195
|
+
$scope.innerDate.value = $scope.formatDate($scope.model);
|
|
196
|
+
$timeout(function () {
|
|
197
|
+
if ($scope.onChange) $scope.onChange({ model: $scope.model });
|
|
198
|
+
$scope.forma.$setDirty();
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// Enter parses the text first, so the form is submitted with the typed date.
|
|
203
|
+
// Enter and Tab also close the picker (it isn't closed on blur, because clicking a day blurs the input).
|
|
204
|
+
$scope.typedDateKeydown = function (event) {
|
|
205
|
+
if (event.keyCode == 13) $scope.parseTypedDate();
|
|
206
|
+
if (event.keyCode == 13 || event.keyCode == 9) $scope.isOpen = false;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
|
|
163
210
|
// ------------------ Clear ------------------
|
|
164
211
|
$scope.clear = function () {
|
|
165
212
|
$scope.isOpen = false;
|
|
@@ -41,7 +41,7 @@ angular.module('niceElements')
|
|
|
41
41
|
if ($scope.time === undefined) $scope.time = true;
|
|
42
42
|
if (!$scope.placeholderDate) { $scope.placeholderDate = gettextCatalog.getString("••.••.••••", null, "Nice"); }
|
|
43
43
|
if (!$scope.placeholderTime) { $scope.placeholderTime = gettextCatalog.getString("••:••", null, "Nice"); }
|
|
44
|
-
if (!$scope.model && !$scope.nullable) $scope.model = moment(
|
|
44
|
+
if (!$scope.model && !$scope.nullable) $scope.model = moment().set({ 'second': 0, 'millisecond': 0 });
|
|
45
45
|
$scope.inner = {
|
|
46
46
|
timeModel: angular.copy($scope.model || moment()),
|
|
47
47
|
dateModel: angular.copy($scope.model || moment()),
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<!------------------------- Field ------------------------->
|
|
7
7
|
<div class="nice-field col-xs-12" ng-class="fieldWidth ? fieldWidth : 'col-sm-8'">
|
|
8
8
|
<div class="input-group">
|
|
9
|
-
<input date-range-picker class="form-control date-picker" type="text" options="opts" ng-model="model" />
|
|
9
|
+
<input date-range-picker class="form-control date-picker" type="text" options="opts" ng-model="model" ng-required="required" />
|
|
10
10
|
<span date-range-picker options="opts" ng-model="model" class="input-group-addon">
|
|
11
11
|
<nice-icon icon="icon-calendar"></nice-icon>
|
|
12
12
|
</span>
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
</span>
|
|
22
22
|
</div>
|
|
23
23
|
|
|
24
|
+
<!-- Only for form validation (date has to be set when required) -->
|
|
25
|
+
<input class="hidden-input" ng-model="model" ng-required="required" tabindex="-1" />
|
|
26
|
+
|
|
24
27
|
<!-- inject nice-dtp here -->
|
|
25
28
|
<div ng-show="isOpen">
|
|
26
29
|
<nice-dtp model="internalDate" format="{{ format }}" model-format="{{ modelFormat }}" date="{{ isTrue(date) }}" time="{{ isTrue(time) }}" width="{{ width }}" enable-ok-buttons="{{ enableOkButtons }}" lang="{{ lang }}" min-date="{{ minDate }}" max-date="{{ maxDate }}" week-start="{{ weekStart }}" ok-text="{{ okText }}" cancel-text="{{ cancelText }}" closed="closeDtp"></nice-dtp>
|
|
@@ -458,11 +458,20 @@ angular.module('niceElements')
|
|
|
458
458
|
});
|
|
459
459
|
|
|
460
460
|
// Handle required
|
|
461
|
-
$timeout(
|
|
462
|
-
if ($scope.formDropdown) $scope.formDropdown.$setValidity('required', !(!$scope.selected && $scope.required));
|
|
463
|
-
});
|
|
461
|
+
$timeout($scope.checkRequired);
|
|
464
462
|
}
|
|
465
463
|
|
|
464
|
+
// ----------------------------------- Required -----------------------------------
|
|
465
|
+
// Form is invalid when required and nothing is selected
|
|
466
|
+
$scope.checkRequired = function () {
|
|
467
|
+
if ($scope.formDropdown) $scope.formDropdown.$setValidity('required', !(!$scope.selected && $scope.required));
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
// Re-check when required is turned on/off
|
|
471
|
+
$scope.$watch('required', function () {
|
|
472
|
+
$scope.checkRequired();
|
|
473
|
+
});
|
|
474
|
+
|
|
466
475
|
// ----------------------------------- Watch for keydown and keypress -----------------------------------
|
|
467
476
|
// $element.bind("keydown keypress", function (event) {
|
|
468
477
|
// // Arrow Up
|
|
@@ -7,17 +7,6 @@
|
|
|
7
7
|
position: fixed !important;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
.hidden-input {
|
|
11
|
-
height: 0;
|
|
12
|
-
width: 100%;
|
|
13
|
-
position: absolute;
|
|
14
|
-
bottom: 0;
|
|
15
|
-
left: 0;
|
|
16
|
-
padding: 0;
|
|
17
|
-
background: transparent;
|
|
18
|
-
opacity: 0;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
10
|
.open {
|
|
22
11
|
.btn-dropdown {
|
|
23
12
|
background: $nice-focus-bg !important;
|
|
@@ -50,7 +50,10 @@ angular.module('niceElements')
|
|
|
50
50
|
return Number(new Decimal(String(number)).toFixed(decimals, 4));
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
if (
|
|
53
|
+
if ($scope.model === null && $scope.required) {
|
|
54
|
+
// Required and empty: keep the field empty so ng-required marks it invalid
|
|
55
|
+
$scope.internalModel = "";
|
|
56
|
+
} else if (angular.isDefined($scope.model)) {
|
|
54
57
|
$scope.internalModel = roundN((angular.copy($scope.model) * 100), 6);
|
|
55
58
|
} else {
|
|
56
59
|
$scope.internalModel = "0";
|
|
@@ -63,7 +66,8 @@ angular.module('niceElements')
|
|
|
63
66
|
if (parseFloat($scope.internalModel) > 100) $scope.internalModel = 100;
|
|
64
67
|
$scope.model = roundN(parseFloat($scope.internalModel) / 100, 6);
|
|
65
68
|
} else {
|
|
66
|
-
|
|
69
|
+
// Cleared field: null when required (so the form is invalid), otherwise 0
|
|
70
|
+
$scope.model = $scope.required ? null : 0;
|
|
67
71
|
}
|
|
68
72
|
if ($scope.onChange) $scope.onChange({ model: $scope.model });
|
|
69
73
|
};
|
|
@@ -85,11 +89,14 @@ angular.module('niceElements')
|
|
|
85
89
|
$scope.$watch('model', function (value_new, value_old) {
|
|
86
90
|
if (value_new) {
|
|
87
91
|
$scope.internalModel = roundN(angular.copy($scope.model) * 100, 6);
|
|
92
|
+
} else if (value_new === null && $scope.required) {
|
|
93
|
+
$scope.internalModel = "";
|
|
88
94
|
}
|
|
89
95
|
});
|
|
90
96
|
|
|
91
97
|
$scope.$watch('internalModel', function (value_new, value_old) {
|
|
92
|
-
|
|
98
|
+
// Empty field falls back to 0, unless required (then it stays empty and invalid)
|
|
99
|
+
if (!$scope.internalModel && !$scope.required) {
|
|
93
100
|
$scope.internalModel = "0";
|
|
94
101
|
}
|
|
95
102
|
});
|
|
@@ -43,7 +43,6 @@ angular.module('niceElements')
|
|
|
43
43
|
if (!attrs.placeholder) { attrs.placeholder = ''; }
|
|
44
44
|
if (!attrs.fieldWidth) { attrs.fieldWidth = 'col-sm-8'; }
|
|
45
45
|
if (!attrs.labelWidth) { attrs.labelWidth = 'col-sm-4'; }
|
|
46
|
-
if (!attrs.setText) { attrs.setText = ''; }
|
|
47
46
|
|
|
48
47
|
attrs.required = attrs.required === 'true' || attrs.required === true;
|
|
49
48
|
attrs.hideValid = attrs.hideValid === 'true' || attrs.hideValid === true;
|
|
@@ -69,8 +68,9 @@ angular.module('niceElements')
|
|
|
69
68
|
});
|
|
70
69
|
|
|
71
70
|
// Set default text
|
|
71
|
+
// (skip when set-text is not used, so the label of a preset model below is kept)
|
|
72
72
|
scope.$watch("setText", function () {
|
|
73
|
-
scope.modelString = scope.setText;
|
|
73
|
+
if (angular.isDefined(scope.setText)) scope.modelString = scope.setText;
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
// Check if object is defined
|
|
@@ -81,18 +81,12 @@ angular.module('niceElements')
|
|
|
81
81
|
scope.modelString = scope.model;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
scope.$watch('model', function (newValue) {
|
|
91
|
-
if (scope.model && scope.model.id) {
|
|
92
|
-
setValid(true);
|
|
93
|
-
} else {
|
|
94
|
-
setValid(false);
|
|
95
|
-
}
|
|
84
|
+
// When required, an object (with id) has to be selected. Also re-check when
|
|
85
|
+
// `required` changes, so turning it off clears the error.
|
|
86
|
+
scope.$watchGroup(['model', 'required'], function () {
|
|
87
|
+
if (!scope.form) return;
|
|
88
|
+
const hasObject = !!(scope.model && scope.model.id);
|
|
89
|
+
scope.form.$setValidity('objectSelected', !scope.required || hasObject);
|
|
96
90
|
});
|
|
97
91
|
|
|
98
92
|
scope.selectRow = function (obj) {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<!------------------------- Field ------------------------->
|
|
7
7
|
<div class="nice-field col-xs-12" ng-class="[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]" click-outside="close()">
|
|
8
8
|
<div class="nice-search-button input-group" ng-class="{ 'disabled': isDisabled }">
|
|
9
|
-
<input class="form-control" type="text" id="{{ id }}" ng-model="model" placeholder="{{ placeholder }}" ng-disabled="isDisabled" ng-change="updateSearch()" ng-focus="onFocus()" tabindex="{{ tabIndex }}">
|
|
9
|
+
<input class="form-control" type="text" id="{{ id }}" ng-model="model" placeholder="{{ placeholder }}" ng-disabled="isDisabled" ng-change="updateSearch()" ng-focus="onFocus()" ng-required="required" tabindex="{{ tabIndex }}">
|
|
10
10
|
|
|
11
11
|
<button type="button" class="btn input-group-addon" ng-disabled="isDisabled" ng-click="buttonClicked()">
|
|
12
12
|
<nice-icon ng-show="!loading && model != ''" icon="icon-x"></nice-icon>
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
|
|
19
19
|
<!------------------------- Field ------------------------->
|
|
20
20
|
<div class="nice-field col-xs-12" ng-class="[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]">
|
|
21
|
+
<!-- Only for form validation (toggle must be on when required) -->
|
|
22
|
+
<input type="checkbox" class="hidden-input" ng-model="model" ng-required="required" tabindex="-1" />
|
|
23
|
+
|
|
21
24
|
<button type="button" class="nice-toggle-field" ng-click="toggle()" ng-disabled="isDisabled">
|
|
22
25
|
<div class="nice-toggle-field-handle">
|
|
23
26
|
<nice-icon ng-if="showIcons && model" icon="icon-check"></nice-icon>
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
</button>
|
|
26
26
|
|
|
27
27
|
<!-- Input file -->
|
|
28
|
-
<input class="input-file" type="file" accept="{{ accept }}" ng-model="file" ng-required="required" ng-disabled="isDisabled || loading" />
|
|
28
|
+
<input class="input-file" type="file" accept="{{ accept }}" ng-model="file" ng-required="required && !model" ng-disabled="isDisabled || loading" />
|
|
29
29
|
|
|
30
30
|
<!-- Loading -->
|
|
31
31
|
<div class="nice-upload-loading" ng-if="loading">
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
<!------------------------- Field ------------------------->
|
|
7
7
|
<div class="nice-field col-xs-12" ng-class="[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]">
|
|
8
|
+
<!-- Only for form validation (yes or no has to be chosen when required) -->
|
|
9
|
+
<input class="hidden-input" ng-model="model" ng-required="required" tabindex="-1" />
|
|
10
|
+
|
|
8
11
|
<div class="yesno-wrapper noselect">
|
|
9
12
|
<button type="button" class="yesno-yes-bg" ng-click="switch()" tabindex="-1" ng-disabled="isDisabled">{{ yes }}</button>
|
|
10
13
|
<button type="button" class="yesno-no-bg" ng-click="switch()" tabindex="-1" ng-disabled="isDisabled">{{ no }}</button>
|
|
@@ -22,6 +22,23 @@ label.nice {
|
|
|
22
22
|
display: block;
|
|
23
23
|
margin-bottom: 10px;
|
|
24
24
|
|
|
25
|
+
// Invisible input used only for form validation (e.g. ng-required) on components
|
|
26
|
+
// that have no real input. Kept in the layout (not display: none) so the browser
|
|
27
|
+
// can still show its "required" bubble on native form submit.
|
|
28
|
+
// Height must be at least 1px: Chrome shows no bubble for a zero-height checkbox.
|
|
29
|
+
.hidden-input {
|
|
30
|
+
height: 1px;
|
|
31
|
+
width: 100%;
|
|
32
|
+
position: absolute;
|
|
33
|
+
bottom: 0;
|
|
34
|
+
left: 0;
|
|
35
|
+
padding: 0;
|
|
36
|
+
border: 0;
|
|
37
|
+
background: transparent;
|
|
38
|
+
opacity: 0;
|
|
39
|
+
pointer-events: none;
|
|
40
|
+
}
|
|
41
|
+
|
|
25
42
|
select,
|
|
26
43
|
input,
|
|
27
44
|
textarea {
|