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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nice-elements",
3
- "version": "1.9.14",
3
+ "version": "1.9.15",
4
4
  "description": "Nice elements used in olaii angular 1.x webapps.",
5
5
  "main": "dist/nice.js",
6
6
  "license": "MIT",
@@ -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: '=', // Allow only positive numbers in the input
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
- if (!attrs.type) { attrs.type = 'text'; }
46
- if (!attrs.title) { attrs.title = ''; }
47
- if (!attrs.regex) { attrs.regex = null; }
48
- if (!attrs.placeholder) { attrs.placeholder = ''; }
49
- if (!attrs.minlength) { attrs.minlength = 1; }
50
- if (!attrs.maxlength) { attrs.maxlength = 100; }
51
- if (!attrs.fieldWidth) { attrs.fieldWidth = 'col-sm-8'; }
52
- if (!attrs.labelWidth) { attrs.labelWidth = 'col-sm-4'; }
53
- if (!attrs.textAreaLines) { attrs.textAreaLines = 3; }
54
- if (!attrs.symbol) { attrs.symbol = ''; }
55
- if (!attrs.help) { attrs.help = ''; }
56
- if (!attrs.name) { attrs.name = ''; }
57
- if (!attrs.minDecimalsCutZeros) { attrs.minDecimalsCutZeros = 0; }
58
- attrs.hideValid = angular.isDefined(attrs.hideValid);
59
- attrs.showValid = angular.isDefined(attrs.showValid);
60
- attrs.textArea = angular.isDefined(attrs.textArea);
61
- attrs.noMargin = angular.isDefined(attrs.noMargin);
62
- attrs.required = attrs.required === 'true';
63
- scope.inputMode = null;
64
- //attrs.required = angular.isDefined(attrs.required);
65
-
66
- if (!scope.textArea) {
67
- scope.elementType = "input";
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
- var input = element[0].getElementsByTagName(scope.elementType)[0];
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 = attrs.type;
83
- if (attrs.type == "percent") {
84
- scope.internalType = "percent";
85
- scope.inputMode = "decimal";
86
- attrs.symbol = '%';
87
- } else if (attrs.type == "number") {
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 (attrs.type == "integer") {
96
- scope.internalType = "text";
97
- scope.inputMode = "numeric";
98
- scope.model = Number(scope.model);
99
- } else if (attrs.type == "email") {
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(attrs.valid)) {
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(attrs.minDecimalsCutZeros) && attrs.type == 'number') {
110
- scope.model = Number(scope.model);
111
- if (scope.model.toString().split('.').length < 2 || scope.model.toString().split('.')[1].length < parseInt(attrs.minDecimalsCutZeros)) {
112
- scope.model = Number((Number(scope.model)).toFixed(parseInt(attrs.minDecimalsCutZeros)));
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.internalModel = angular.copy(scope.model);
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 (attrs.type == "number" && value_new) {
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
- if (scope.onChange) scope.onChange({ model: scope.model });
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
- if (scope.onChange) scope.onChange({ model: scope.model });
148
+ $scope.model = angular.copy($scope.internalModel);
149
+ $scope.handleChange();
142
150
  }
143
151
  } else {
144
- scope.model = angular.copy(scope.internalModel);
145
- if (scope.onChange) scope.onChange({ model: scope.model });
152
+ $scope.model = angular.copy($scope.internalModel);
153
+ $scope.handleChange();
146
154
  }
147
155
  });
148
- },
149
156
 
150
- controller: function ($scope, $rootScope, ngDialog) {
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
@@ -81,7 +81,7 @@ angular.module('niceElements')
81
81
  }
82
82
 
83
83
  if ($scope.onChange) $scope.onChange({ model: $scope.model });
84
- $scope.formYesno.$setDirty();
84
+ $scope.formToggle.$setDirty();
85
85
  }
86
86
  };
87
87
 
@@ -10,7 +10,7 @@ angular.module('niceElements')
10
10
  .service('NiceService', function () {
11
11
  var service = {
12
12
  name: "Nice elements",
13
- version: "1.9.14",
13
+ version: "1.9.15",
14
14
  getHeader: function () {
15
15
  return {};
16
16
  }