nice-elements 1.9.14 → 1.9.15
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/CHANGELOG.md +6 -0
- package/LICENSE.md +1 -1
- package/README.md +1 -1
- package/bower.json +1 -1
- package/dist/nice.js +87 -74
- package/dist/nice.min.js +1 -1
- package/package.json +1 -1
- package/src/components/nice-input/nice-input.js +86 -73
- package/src/components/nice-toggle/nice-toggle.js +1 -1
- package/src/services/nice-service.js +1 -1
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
angular.module('niceElements')
|
|
2
|
-
.directive('niceInput', function () {
|
|
2
|
+
.directive('niceInput', function ($timeout) {
|
|
3
3
|
return {
|
|
4
4
|
templateUrl: 'src/components/nice-input/nice-input.html',
|
|
5
5
|
restrict: 'E',
|
|
@@ -36,118 +36,131 @@ angular.module('niceElements')
|
|
|
36
36
|
onChange: '&?',
|
|
37
37
|
onClear: '&?',
|
|
38
38
|
numbersOnly: '=', // Allow only numbers in the input
|
|
39
|
-
positiveOnly: '
|
|
39
|
+
positiveOnly: '=?', // Allow only positive numbers in the input
|
|
40
40
|
multilanguage: '=?', // Multiple languages object
|
|
41
41
|
multilanguageField: '@?', // Multiple languages field name
|
|
42
42
|
},
|
|
43
43
|
|
|
44
44
|
link: function (scope, element, attrs) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
if (
|
|
51
|
-
if (
|
|
52
|
-
if (
|
|
53
|
-
if (
|
|
54
|
-
if (
|
|
55
|
-
if (
|
|
56
|
-
if (
|
|
57
|
-
if (
|
|
58
|
-
attrs.
|
|
59
|
-
attrs.
|
|
60
|
-
attrs.
|
|
61
|
-
attrs.
|
|
62
|
-
attrs.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
45
|
+
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
controller: function ($scope, $attrs, $rootScope, $element, ngDialog) {
|
|
49
|
+
if (!$attrs.type) { $attrs.type = 'text'; }
|
|
50
|
+
if (!$attrs.title) { $attrs.title = ''; }
|
|
51
|
+
if (!$attrs.regex) { $attrs.regex = null; }
|
|
52
|
+
if (!$attrs.placeholder) { $attrs.placeholder = ''; }
|
|
53
|
+
if (!$attrs.minlength) { $attrs.minlength = 1; }
|
|
54
|
+
if (!$attrs.maxlength) { $attrs.maxlength = 100; }
|
|
55
|
+
if (!$attrs.fieldWidth) { $attrs.fieldWidth = 'col-sm-8'; }
|
|
56
|
+
if (!$attrs.labelWidth) { $attrs.labelWidth = 'col-sm-4'; }
|
|
57
|
+
if (!$attrs.textAreaLines) { $attrs.textAreaLines = 3; }
|
|
58
|
+
if (!$attrs.symbol) { $attrs.symbol = ''; }
|
|
59
|
+
if (!$attrs.help) { $attrs.help = ''; }
|
|
60
|
+
if (!$attrs.name) { $attrs.name = ''; }
|
|
61
|
+
if (!$attrs.minDecimalsCutZeros) { $attrs.minDecimalsCutZeros = 0; }
|
|
62
|
+
$attrs.hideValid = angular.isDefined($attrs.hideValid);
|
|
63
|
+
$attrs.showValid = angular.isDefined($attrs.showValid);
|
|
64
|
+
$attrs.textArea = angular.isDefined($attrs.textArea);
|
|
65
|
+
$attrs.noMargin = angular.isDefined($attrs.noMargin);
|
|
66
|
+
$attrs.required = $attrs.required === 'true';
|
|
67
|
+
$scope.inputMode = null;
|
|
68
|
+
$scope.lastKey = null;
|
|
69
|
+
|
|
70
|
+
if (!$scope.textArea) {
|
|
71
|
+
$scope.elementType = "input";
|
|
68
72
|
} else {
|
|
69
|
-
scope.elementType = "textarea";
|
|
73
|
+
$scope.elementType = "textarea";
|
|
70
74
|
}
|
|
71
75
|
|
|
72
|
-
if (scope.isFocused) {
|
|
73
|
-
|
|
76
|
+
if ($scope.isFocused) {
|
|
77
|
+
const input = $element[0].getElementsByTagName($scope.elementType)[0];
|
|
74
78
|
if (input) input.focus();
|
|
75
79
|
}
|
|
76
80
|
|
|
77
|
-
if (scope.numbersOnly) {
|
|
78
|
-
scope.inputMode = "numeric";
|
|
81
|
+
if ($scope.numbersOnly) {
|
|
82
|
+
$scope.inputMode = "numeric";
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
// Set internal type
|
|
82
|
-
scope.internalType =
|
|
83
|
-
if (
|
|
84
|
-
scope.internalType = "percent";
|
|
85
|
-
scope.inputMode = "decimal";
|
|
86
|
-
|
|
87
|
-
} else if (
|
|
88
|
-
scope.internalType = "text";
|
|
89
|
-
scope.inputMode = "decimal";
|
|
90
|
-
if (scope.model != null) {
|
|
91
|
-
scope.model = Number(scope.model);
|
|
86
|
+
$scope.internalType = $scope.type;
|
|
87
|
+
if ($scope.type == "percent") {
|
|
88
|
+
$scope.internalType = "percent";
|
|
89
|
+
$scope.inputMode = "decimal";
|
|
90
|
+
$scope.symbol = '%';
|
|
91
|
+
} else if ($scope.type == "number") {
|
|
92
|
+
$scope.internalType = "text";
|
|
93
|
+
$scope.inputMode = "decimal";
|
|
94
|
+
if ($scope.model != null) {
|
|
95
|
+
$scope.model = Number($scope.model);
|
|
92
96
|
} else {
|
|
93
|
-
scope.model = null;
|
|
97
|
+
$scope.model = null;
|
|
94
98
|
}
|
|
95
|
-
} else if (
|
|
96
|
-
scope.internalType = "text";
|
|
97
|
-
scope.inputMode = "numeric";
|
|
98
|
-
scope.model = Number(scope.model);
|
|
99
|
-
} else if (
|
|
100
|
-
scope.inputMode = "email";
|
|
99
|
+
} else if ($scope.type == "integer") {
|
|
100
|
+
$scope.internalType = "text";
|
|
101
|
+
$scope.inputMode = "numeric";
|
|
102
|
+
$scope.model = Number($scope.model);
|
|
103
|
+
} else if ($scope.type == "email") {
|
|
104
|
+
$scope.inputMode = "email";
|
|
101
105
|
// TODO: get rid of the errors
|
|
102
|
-
scope.regexexp = new RegExp('^[_a-zA-Z0-9]+(.[_a-zA-Z0-9]+)*@[a-zA-Z0-9]+(.[a-zA-Z0-9]+)+(.[a-zA-Z]{2,4})');
|
|
106
|
+
$scope.regexexp = new RegExp('^[_a-zA-Z0-9]+(.[_a-zA-Z0-9]+)*@[a-zA-Z0-9]+(.[a-zA-Z0-9]+)+(.[a-zA-Z]{2,4})');
|
|
103
107
|
}
|
|
104
108
|
|
|
105
|
-
if (angular.isDefined(
|
|
106
|
-
scope.valid = scope.forma;
|
|
109
|
+
if (angular.isDefined($scope.valid)) {
|
|
110
|
+
$scope.valid = $scope.forma;
|
|
107
111
|
}
|
|
108
112
|
|
|
109
|
-
if (scope.model && angular.isDefined(
|
|
110
|
-
scope.model = Number(scope.model);
|
|
111
|
-
if (scope.model.toString().split('.').length < 2 || scope.model.toString().split('.')[1].length < parseInt(
|
|
112
|
-
scope.model = Number((Number(scope.model)).toFixed(parseInt(
|
|
113
|
+
if ($scope.model && angular.isDefined($scope.minDecimalsCutZeros) && $scope.type == 'number') {
|
|
114
|
+
$scope.model = Number($scope.model);
|
|
115
|
+
if ($scope.model.toString().split('.').length < 2 || $scope.model.toString().split('.')[1].length < parseInt($scope.minDecimalsCutZeros)) {
|
|
116
|
+
$scope.model = Number((Number($scope.model)).toFixed(parseInt($scope.minDecimalsCutZeros)));
|
|
113
117
|
}
|
|
114
118
|
}
|
|
115
119
|
|
|
116
|
-
if (angular.isDefined(scope.regex) && scope.regex != '') {
|
|
117
|
-
scope.regexexp = new RegExp(scope.regex);
|
|
120
|
+
if (angular.isDefined($scope.regex) && $scope.regex != '') {
|
|
121
|
+
$scope.regexexp = new RegExp($scope.regex);
|
|
118
122
|
}
|
|
119
123
|
|
|
120
|
-
if (angular.isDefined(scope.regexRaw) && scope.regexRaw != '') {
|
|
121
|
-
scope.regexexp = regexRaw;
|
|
124
|
+
if (angular.isDefined($scope.regexRaw) && $scope.regexRaw != '') {
|
|
125
|
+
$scope.regexexp = regexRaw;
|
|
122
126
|
}
|
|
123
127
|
|
|
124
|
-
scope.$watch('model', function (value_new, value_old) {
|
|
125
|
-
scope.
|
|
128
|
+
$scope.$watch('model', function (value_new, value_old) {
|
|
129
|
+
if ($scope.type == "number" && value_old && value_old[value_old.length-1] == ".") {
|
|
130
|
+
|
|
131
|
+
} else {
|
|
132
|
+
$scope.internalModel = angular.copy($scope.model);
|
|
133
|
+
}
|
|
126
134
|
|
|
127
135
|
// Check if number is positive
|
|
128
|
-
if (scope.type == "number" && scope.positiveOnly) {
|
|
129
|
-
scope.forma.$setValidity('positiveOnly', Number(scope.model) >= 0);
|
|
136
|
+
if ($scope.type == "number" && $scope.positiveOnly) {
|
|
137
|
+
$scope.forma.$setValidity('positiveOnly', Number($scope.model) >= 0);
|
|
130
138
|
}
|
|
131
139
|
});
|
|
132
140
|
|
|
133
|
-
scope.$watch('internalModel', function (value_new, value_old) {
|
|
134
|
-
if (
|
|
141
|
+
$scope.$watch('internalModel', function (value_new, value_old) {
|
|
142
|
+
if ($scope.type == "number" && value_new) {
|
|
135
143
|
if (typeof value_new != "number") {
|
|
136
|
-
scope.internalModel = value_new.replace(',', '.');
|
|
137
|
-
scope.model = angular.copy(scope.internalModel);
|
|
138
|
-
|
|
144
|
+
$scope.internalModel = value_new.replace(',', '.');
|
|
145
|
+
$scope.model = angular.copy($scope.internalModel);
|
|
146
|
+
$scope.handleChange();
|
|
139
147
|
} else {
|
|
140
|
-
scope.model = angular.copy(scope.internalModel);
|
|
141
|
-
|
|
148
|
+
$scope.model = angular.copy($scope.internalModel);
|
|
149
|
+
$scope.handleChange();
|
|
142
150
|
}
|
|
143
151
|
} else {
|
|
144
|
-
scope.model = angular.copy(scope.internalModel);
|
|
145
|
-
|
|
152
|
+
$scope.model = angular.copy($scope.internalModel);
|
|
153
|
+
$scope.handleChange();
|
|
146
154
|
}
|
|
147
155
|
});
|
|
148
|
-
},
|
|
149
156
|
|
|
150
|
-
|
|
157
|
+
$scope.handleChange = function() {
|
|
158
|
+
if ($scope.onChange) {
|
|
159
|
+
$timeout(function() {
|
|
160
|
+
$scope.onChange({ model: $scope.model });
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
}
|
|
151
164
|
$scope.id = Math.random().toString(36).substring(7);
|
|
152
165
|
|
|
153
166
|
// Handle multiple language field if empty
|