fng-ui-select 0.12.0-beta.33 → 0.12.0-beta.331

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.
Files changed (44) hide show
  1. package/.github/workflows/playwright.yml +38 -0
  2. package/README.md +1 -1
  3. package/package.json +8 -8
  4. package/playwright.config.js +81 -0
  5. package/playwright.config.ts +77 -0
  6. package/src/fng-ui-select.js +263 -110
  7. package/styles/fng-ui-select.css +13 -4
  8. package/test/playwright/select.spec.js +75 -0
  9. package/test/playwright/select.spec.ts +69 -0
  10. package/test/playwright/tsconfig.json +10 -0
  11. package/test/e2e/multi-control.spec.js +0 -94
  12. package/test/e2e/multiple-control.spec.js +0 -175
  13. package/test/e2e/protractor-chrome.conf.js +0 -10
  14. package/test/e2e/protractor-firefox.conf.js +0 -38
  15. package/test/e2e/protractor-phantom.conf.js +0 -10
  16. package/test/e2e/protractor-wip.conf.js +0 -10
  17. package/test/e2e/single-control.spec.js +0 -86
  18. package/test/e2e/single-within-array.spec.js +0 -95
  19. package/test/e2e/test/screen_tests/screenshots/firefox-Multi control-should convert multi ajax lookups into multiple controls.png +0 -0
  20. package/test/e2e/test/screen_tests/screenshots/firefox-Multi control-should handle inside cached lookups.png +0 -0
  21. package/test/e2e/test/screen_tests/screenshots/firefox-Multi control-should handle outside cached lookups.png +0 -0
  22. package/test/e2e/test/screen_tests/screenshots/firefox-Multi control-should handle simple enum.png +0 -0
  23. package/test/e2e/test/screen_tests/screenshots/firefox-Multiple controls array-should handle inside brackets ajax lookup.png +0 -0
  24. package/test/e2e/test/screen_tests/screenshots/firefox-Multiple controls array-should handle inside brackets cached table lookups.png +0 -0
  25. package/test/e2e/test/screen_tests/screenshots/firefox-Multiple controls array-should handle outside brackets ajax lookup.png +0 -0
  26. package/test/e2e/test/screen_tests/screenshots/firefox-Multiple controls array-should handle outside brackets cached table lookups.png +0 -0
  27. package/test/e2e/test/screen_tests/screenshots/firefox-Multiple controls array-should handle simple enums.png +0 -0
  28. package/test/e2e/test/screen_tests/screenshots/firefox-Single control-should handle Ajax lookup.png +0 -0
  29. package/test/e2e/test/screen_tests/screenshots/firefox-Single control-should handle cached table lookup.png +0 -0
  30. package/test/e2e/test/screen_tests/screenshots/firefox-Single control-should handle filtered Ajax lookup.png +0 -0
  31. package/test/e2e/test/screen_tests/screenshots/firefox-Single control-should handle simple enum.png +0 -0
  32. package/test/screen_tests/screenshots/firefox-Multi control-should convert multi ajax lookups into multiple controls.png +0 -0
  33. package/test/screen_tests/screenshots/firefox-Multi control-should handle inside cached lookups.png +0 -0
  34. package/test/screen_tests/screenshots/firefox-Multi control-should handle outside cached lookups.png +0 -0
  35. package/test/screen_tests/screenshots/firefox-Multi control-should handle simple enum.png +0 -0
  36. package/test/screen_tests/screenshots/firefox-Multiple controls array-should handle inside brackets ajax lookup.png +0 -0
  37. package/test/screen_tests/screenshots/firefox-Multiple controls array-should handle inside brackets cached table lookups.png +0 -0
  38. package/test/screen_tests/screenshots/firefox-Multiple controls array-should handle outside brackets ajax lookup.png +0 -0
  39. package/test/screen_tests/screenshots/firefox-Multiple controls array-should handle outside brackets cached table lookups.png +0 -0
  40. package/test/screen_tests/screenshots/firefox-Multiple controls array-should handle simple enums.png +0 -0
  41. package/test/screen_tests/screenshots/firefox-Single control-should handle Ajax lookup.png +0 -0
  42. package/test/screen_tests/screenshots/firefox-Single control-should handle cached table lookup.png +0 -0
  43. package/test/screen_tests/screenshots/firefox-Single control-should handle filtered Ajax lookup.png +0 -0
  44. package/test/screen_tests/screenshots/firefox-Single control-should handle simple enum.png +0 -0
@@ -3,9 +3,44 @@
3
3
 
4
4
  var uiSelectModule = angular.module('fng.uiSelect', ['ui.select']);
5
5
 
6
- uiSelectModule.factory('uiSelectHelper', ['$rootScope', '$q', 'SubmissionsService', function ($rootScope, $q, SubmissionsService) {
6
+ uiSelectModule.factory('FngUISelectHelperService', ['$rootScope', '$q', 'RecordHandlerService', 'SubmissionsService', function ($rootScope, $q, RecordHandlerService, SubmissionsService) {
7
7
  var lastW, lastH;
8
- var localLookups = {};
8
+ const localLookups = {};
9
+ // this ultra-simple cache stores { [id: string]: stringValue } as a means of avoiding unnecessary network round-trips, and the UI refresh
10
+ // lagging caused by the promises used to make them.
11
+ // there is no cache life-span because all we're storing here is the concatenation of records' list fields, and the chances of those
12
+ // changing while present in this cache is miniscule. even if they did change, displaying a stale record description in a picklist
13
+ // would surely not cause any great concern.
14
+ // there is no cache size limit because we're storing tiny amounts of data.
15
+ // NB: this cache assumes that record ids are unique across all resources (as is the case with a standard MongoDB back-end).
16
+ // TODO: provide an alternative implementation that includes the resourceName in the cache ids to avoid this limitation.
17
+ let valueCache = {};
18
+ // we're going to populate the select with this value whenever a SubmissionsService.getListAttributes(...) call is rejected. because we're
19
+ // only asking for list fields, permissions should not be the cause of failures, making "record not found" (where the foreign key
20
+ // reference has been broken) by far the most likely explanation.
21
+ // TODO: interpret the actual error condition and translate this into a user-friendly message
22
+ const RECORD_NOT_FOUND = "record not found";
23
+
24
+ function useCacheOrLookItUp(resourceName, id, cb) {
25
+ if (valueCache[id]) {
26
+ cb(valueCache[id]);
27
+ } else {
28
+ var text;
29
+ SubmissionsService.getListAttributes(resourceName, id)
30
+ .then((response) => {
31
+ text = response.data.list;
32
+ })
33
+ .catch(() => {
34
+ text = RECORD_NOT_FOUND; // cache this as well as there's no point in repeatedly performing a failing lookup
35
+ })
36
+ .finally(() => {
37
+ cb(text);
38
+ valueCache[id] = text;
39
+ })
40
+ }
41
+ }
42
+
43
+ // NB: the type defs for this service (IFngUISelectHelperService) are in the forms-angular's index.d.ts
9
44
  return {
10
45
  windowChanged: function (w, h) {
11
46
  var result = false;
@@ -19,53 +54,78 @@
19
54
  addClientLookup: function (lkpName, lkpData) {
20
55
  localLookups[lkpName] = lkpData;
21
56
  },
57
+ clearCache: function () {
58
+ valueCache = {};
59
+ },
22
60
  lookupFunc: function (value, formSchema, cb) {
23
61
  if (formSchema.array) {
24
- // TODO extend back end to do multiple lookups in one hit
25
-
26
- var promises = [];
27
- var results = [];
28
- angular.forEach(value, function (obj) {
29
- promises.push(SubmissionsService.getListAttributes(formSchema.ref, obj.x));
30
- });
31
- $q.all(promises).then(function (responses) {
32
- angular.forEach(responses, function (response) {
33
- results.push({x: {id: value.shift().x, text: response.data.list}});
62
+ if (formSchema.fngUiSelect.deriveOptions) {
63
+ const results = value.map((value) => {
64
+ const obj = localLookups[formSchema.fngUiSelect.deriveOptions].find((test) => test.id === value);
65
+ return { id: value, text: obj ? obj.text : "" };
34
66
  });
35
67
  cb(formSchema, results);
36
- setTimeout(function () {
37
- $rootScope.$digest();
68
+ if (results.length > 0) {
69
+ setTimeout(function () {
70
+ $rootScope.$digest();
71
+ });
72
+ }
73
+ } else {
74
+ const promises = value.map((value) => {
75
+ const id = value.x ? (value.x.id || value.x) : value; // if it's already been converted, throw away the result of the previous conversion
76
+ if (!id) {
77
+ return $q.resolve({ data: { list: "" } }); // nothing to convert
78
+ } else if (valueCache[id]) {
79
+ return $q.resolve({ data: { list: valueCache[id] } }); // already cached
80
+ } else {
81
+ return SubmissionsService.getListAttributes(formSchema.ref, id); // need to look it up
82
+ }
38
83
  });
39
- });
40
- } else if (formSchema.fngUiSelect.deriveOptions) {
41
- var retVal;
42
- if (typeof value === 'string') {
43
- var obj = localLookups[formSchema.fngUiSelect.deriveOptions].find(function (test) {
44
- return test.id === value
84
+ // TODO: no error handling here
85
+ // TODO: perform lookups of cache misses using a single round-trip
86
+ $q.all(promises).then((responses) => {
87
+ const results = responses.map((response) => {
88
+ let id = value.shift().x;
89
+ id = id.id || id; // in case it's already been converted
90
+ const text = response.data.list
91
+ valueCache[id] = text; // cache it for next time
92
+ return { id, text }
93
+ });
94
+ cb(formSchema, results);
95
+ setTimeout(function () {
96
+ $rootScope.$digest();
97
+ });
45
98
  });
46
- retVal = {id: value, text: obj ? obj.text : ''}
47
- } else {
48
- retVal = value;
49
99
  }
50
- cb(formSchema, retVal);
100
+ } else if (typeof value !== "string") {
101
+ cb(formSchema, value); // already converted
102
+ } else if (formSchema.fngUiSelect && formSchema.fngUiSelect.deriveOptions) {
103
+ const obj = localLookups[formSchema.fngUiSelect.deriveOptions].find((test) => test.id === value);
104
+ cb(formSchema, { id: value, text: obj ? obj.text : "" });
51
105
  } else {
52
- SubmissionsService.getListAttributes(formSchema.ref, value).then(function (response) {
53
- cb(formSchema, {id: value, text: response.data.list});
54
- });
106
+ useCacheOrLookItUp(formSchema.ref, value, (text) => { cb(formSchema, { id: value, text }) });
107
+ }
108
+ },
109
+ doOwnConversion: function (scope, processedAttrs, ref) {
110
+ var id = RecordHandlerService.getData(scope.record, processedAttrs.info.name, scope.$index);
111
+ if (id) {
112
+ id = id.id || id; // in case it's already been converted
113
+ useCacheOrLookItUp(ref, id, (text) => { RecordHandlerService.setData(scope.record, processedAttrs.info.name, scope.$index, { id, text }) });
55
114
  }
56
115
  }
57
116
  };
58
117
  }]);
59
118
 
60
119
 
61
- uiSelectModule.controller('FngUISelectCtrl', ['$scope', '$window', '$timeout', '$http', 'uiSelectHelper', function ($scope, $window, $timeout, $http, uiSelectHelper) {
120
+ uiSelectModule.controller('FngUISelectCtrl', ['$scope', '$window', '$timeout', '$http', 'FngUISelectHelperService', function ($scope, $window, $timeout, $http, FngUISelectHelperService) {
62
121
 
63
122
  $scope.uiSelect = $scope.uiSelect || [];
64
123
 
65
124
  $scope.windowResizeUiSelect = function (checkResize) {
66
- // This is to stop the resize firing too often. Really horrible way of doing it caused by some very regrettable design choices which will be factored out later
125
+ // This is to stop the resize firing too often. Really horrible way of doing it caused by some very regrettable
126
+ // design choices which will be factored out later
67
127
  // Actually not choices - just not knowing any better
68
- if (!checkResize || uiSelectHelper.windowChanged($window.innerWidth, $window.innerHeight)) {
128
+ if (!checkResize || FngUISelectHelperService.windowChanged($window.innerWidth, $window.innerHeight)) {
69
129
  for (var i = 0; i < $scope.uiSelect.length; i++) {
70
130
  var selectId = $scope.uiSelect[i].selectId;
71
131
  var select = document.getElementById(selectId);
@@ -94,14 +154,23 @@
94
154
  $scope[id + '_options'] = [];
95
155
  } else {
96
156
  var promise;
97
- if (elem.filter && elem.filter[0] === '/') {
157
+ if (elem.filter && typeof elem.filter === "string" && elem.filter[0] === "/") {
158
+ if (elem.filter.startsWith("/api/")) {
159
+ console.log("WARNING! fng-ui-select is using an /api/ endpoint to refresh options - this is likely to cause security authorisation problems");
160
+ }
161
+ // HACK We want to pass the existing record in e, but we can fall foul of 431 errors if it is large, so we test for that
162
+ // using an arbitrary number and if so just send the _id (on the assumption that large records won't be new so will have an _id).
163
+ // According to https://stackoverflow.com/questions/57431355/how-to-fix-431-request-header-fields-too-large-in-react-redux-app the limit is 8KB
164
+ // but I have seen it fail at about 5k...
165
+ var record = JSON.stringify($scope.record).length >= (4 * 1024) ? { _id: $scope.record._id } : $scope.record;
98
166
  // Custom URL
99
167
  promise = $http({
100
168
  method: 'GET',
101
169
  url: elem.filter,
102
170
  params: {
103
171
  q: searchString,
104
- e: $scope.record
172
+ e: record,
173
+ i: $scope.$index
105
174
  },
106
175
  cache: false
107
176
  });
@@ -122,9 +191,15 @@
122
191
  }
123
192
  }
124
193
  })
125
- .catch(err => {
126
- $scope.showError(err.data);
127
- });
194
+ .catch(function (err) {
195
+ var msg;
196
+ if (err && err.data && err.data.message) {
197
+ msg = err.data.message;
198
+ } else {
199
+ msg = 'Error ' + err.status + ': ' + err.statusText + ' - ' + err.data;
200
+ }
201
+ $scope.showError(msg);
202
+ });
128
203
  }
129
204
  } else {
130
205
  throw new Error('Could not find uiSelect element for ' + id);
@@ -139,50 +214,71 @@
139
214
  $timeout($scope.windowResizeUiSelect);
140
215
  }]);
141
216
 
142
- uiSelectModule.directive('fngUiSelect', ['$compile', '$window', 'pluginHelper', 'cssFrameworkService', 'formMarkupHelper', 'uiSelectHelper',
143
- function ($compile, $window, pluginHelper, cssFrameworkService, formMarkupHelper, uiSelectHelper) {
217
+ uiSelectModule.directive('fngUiSelect', ['$compile', 'PluginHelperService', 'CssFrameworkService', 'FngUISelectHelperService', '$timeout',
218
+ function ($compile, PluginHelperService, CssFrameworkService, FngUISelectHelperService, $timeout) {
144
219
  return {
145
220
  restrict: 'E',
146
221
  controller: 'FngUISelectCtrl',
147
- link: function (scope, element, attr) {
222
+ link: function (scope, element, attrs) {
148
223
 
149
224
  function addToConversions(path, options) {
150
225
  if (Object.keys(options).length > 0) {
151
226
  var keys = path.split('.');
152
- if (!scope.conversions) {
153
- scope.conversions = {};
227
+
228
+ // Find the scope that owns the form (where the watcher is)
229
+ var conversionScope = scope;
230
+ while (conversionScope.$parent && !conversionScope.hasOwnProperty('topLevelFormName')) {
231
+ conversionScope = conversionScope.$parent;
232
+ }
233
+
234
+ if (!conversionScope.conversions) {
235
+ conversionScope.conversions = {};
154
236
  }
155
- var target = scope.conversions;
237
+ var target = conversionScope.conversions;
156
238
  for (var i = 0; i < keys.length; i++) {
157
239
  var thisKey = keys[i];
158
240
  target[thisKey] = target[thisKey] || {};
159
241
  target = target[thisKey];
160
242
  }
161
243
  angular.extend(target, options);
244
+ conversionScope.conversionsModified = true;
162
245
  }
163
246
  }
164
247
 
165
- var processedAttr = pluginHelper.extractFromAttr(attr, 'fngUiSelect');
166
- var elemScope = angular.extend({selectId: processedAttr.info.id}, processedAttr.directiveOptions);
167
- var multi = processedAttr.info.array;
168
- var elementHtml;
169
- var input = '';
248
+ const processedAttrs = PluginHelperService.extractFromAttr(attrs, 'fngUiSelect', scope);
249
+ const id = processedAttrs.info.id;
250
+ const uniqueId = scope.$index !== undefined ? processedAttrs.info.id + "_" + scope.$index : id;
251
+ const elemScope = angular.extend({ selectId: uniqueId }, processedAttrs.directiveOptions);
252
+ const multi = processedAttrs.info.array;
253
+ let elementHtml;
254
+ let input = '';
170
255
 
171
256
  scope.uiSelect.push(elemScope);
172
- addToConversions(processedAttr.info.name, processedAttr.directiveOptions);
257
+ addToConversions(processedAttrs.info.name, processedAttrs.directiveOptions);
173
258
 
174
259
  // Sort out the theme, defaulting to select2 (so old users won't see the change). Bootstrap theme only works with Bootstrap 3
175
- var theme = processedAttr.directiveOptions.theme || 'select2';
176
- if (processedAttr.info.theme === 'bootstrap' && cssFrameworkService.framework !== 'bs3') {
177
- theme = 'select2';
260
+ // and not with animate (see https://github.com/angular-ui/ui-select/issues/1731 and others)
261
+ var theme = processedAttrs.directiveOptions.theme || 'select2';
262
+ if (theme === 'bootstrap') {
263
+ if (CssFrameworkService.framework() !== 'bs3') {
264
+ theme = 'select2';
265
+ } else {
266
+ try {
267
+ if (angular.module('ngAnimate')) {
268
+ theme = 'select2';
269
+ }
270
+ } catch (e) {
271
+ ; // module not present, so bootstrap theme will work
272
+ }
273
+ }
178
274
  }
179
275
 
180
276
  var multiControl = false;
181
277
  var multiStr = '';
182
- if (multi && (processedAttr.directiveOptions.fngajax || processedAttr.directiveOptions.forcemultiple)) {
278
+ if (multi && (processedAttrs.directiveOptions.fngajax || processedAttrs.directiveOptions.forcemultiple)) {
183
279
  // We need the array to be an array of objects with a x property. This tells forms-angular to convert it by
184
280
  // adding an attribute to the schema.
185
- pluginHelper.findIdInSchemaAndFlagNeedX(scope.baseSchema(), processedAttr.info.id);
281
+ PluginHelperService.findIdInSchemaAndFlagNeedX(scope.baseSchema(), id);
186
282
  multiControl = true;
187
283
  } else {
188
284
  multiStr = multi ? 'multiple close-on-select reset-search-input ' : '';
@@ -190,36 +286,52 @@
190
286
 
191
287
  var requiredStr = '';
192
288
  var allowClearStr = '';
193
- if (processedAttr.info.required) {
289
+ if (processedAttrs.info.required) {
194
290
  requiredStr = ' ng-required="true"';
291
+ } else if (processedAttrs.directiveOptions.ngrequired) {
292
+ requiredStr = ` ng-required="${processedAttrs.directiveOptions.ngrequired}"`;
195
293
  } else {
196
294
  allowClearStr = ' allow-clear';
197
295
  }
296
+ let disabledStr = PluginHelperService.genIdAndDisabledStr(scope, processedAttrs, "", { forceNg: true });
198
297
 
199
298
  // First of all add a hidden input field which we will use to set the width of the select
200
- var hiddenInputInfo = {
201
- id: processedAttr.info.id + '_width-helper',
202
- name: processedAttr.info.name + '_width-helper',
203
- label: ''
204
- };
205
- if (processedAttr.info.size) {
206
- hiddenInputInfo.size = processedAttr.info.size;
299
+ if (!angular.element(`#${uniqueId}_width-helper`).length > 0) {
300
+ var hiddenInputInfo = {
301
+ id: `${uniqueId}_width-helper`,
302
+ name: processedAttrs.info.name + '_width-helper',
303
+ label: ''
304
+ };
305
+ if (processedAttrs.info.size) {
306
+ hiddenInputInfo.size = processedAttrs.info.size;
307
+ }
308
+ input = PluginHelperService.buildInputMarkup(
309
+ scope,
310
+ attrs,
311
+ {
312
+ processedAttrs,
313
+ fieldInfoOverrides: hiddenInputInfo,
314
+ ignoreFieldInfoFromAttrs: true,
315
+ needsX: multiControl
316
+ },
317
+ function () {
318
+ return '<input id="' + hiddenInputInfo.id + '" type="text" class="form-control" disabled="" aria-label="unused input" style="position: absolute; left: -4200px;">';
319
+ }
320
+ );
321
+ input = input.replace('class="row', 'class="hidden-row row')
207
322
  }
208
- input = pluginHelper.buildInputMarkup(scope, attr.model, hiddenInputInfo, processedAttr.options, false, multiControl, function (buildingBlocks) {
209
- return '<input id="' + hiddenInputInfo.id + '" type="text" class="form-control" disabled="" style="position: absolute; left: -4200px;">';
210
- });
211
323
 
212
324
  function optionsFromArray(multiControl, multi, array, arrayGetter) {
213
325
  var isObjects = scope[array] && (scope[array].isObjects || typeof scope[array][0] === "object");
214
326
  if (isObjects) {
215
- addToConversions(processedAttr.info.name, {fngajax: uiSelectHelper.lookupFunc});
216
- uiSelectHelper.addClientLookup(arrayGetter, scope[array]);
327
+ addToConversions(processedAttrs.info.name, { fngajax: FngUISelectHelperService.lookupFunc });
328
+ FngUISelectHelperService.addClientLookup(arrayGetter, scope[array]);
217
329
  }
218
330
  var select = '';
219
331
  if (multiControl) {
220
332
  select += '{{$select.selected' + (isObjects ? '.text' : '') + '}}';
221
333
  } else {
222
- select += multi ? '{{$item}}' : ('{{$select.selected' + (isObjects ? '.text' : '') + '}}');
334
+ select += multi ? '{{$item' + (isObjects ? '.text' : '') + '}}' : ('{{$select.selected' + (isObjects ? '.text' : '') + '}}');
223
335
  }
224
336
  select += '</ui-select-match>';
225
337
  select += '<ui-select-choices repeat="option in ' + array + ' | filter:$select.search">';
@@ -227,55 +339,96 @@
227
339
  return select;
228
340
  }
229
341
 
230
- elementHtml = pluginHelper.buildInputMarkup(scope, attr.model, processedAttr.info, processedAttr.options, multiControl, multiControl, function (buildingBlocks) {
231
- var defaultPlaceholder = 'Select an option...';
232
- if (processedAttr.directiveOptions.fngajax) {
233
- defaultPlaceholder = 'Start typing...'
234
- }
235
- // set up the ui-select directives
236
- var select = '<ui-select ' + multiStr + buildingBlocks.common + requiredStr + ' theme="' + theme + '" ng-disabled="disabled" style="width:300px;">';
237
- select += '<ui-select-match' + allowClearStr + ' placeholder="' + (processedAttr.info.placeholder || defaultPlaceholder) + '">';
238
-
239
-
240
- if (processedAttr.directiveOptions.fngajax) {
241
- // Stash any filters
242
- if (processedAttr.directiveOptions.fngajax !== true) {
243
- elemScope.filter = processedAttr.directiveOptions.fngajax;
342
+ elementHtml = PluginHelperService.buildInputMarkup(
343
+ scope,
344
+ attrs,
345
+ {
346
+ processedAttrs,
347
+ addButtons: multiControl,
348
+ needsX: multiControl,
349
+ },
350
+ function (buildingBlocks) {
351
+ var defaultPlaceholder = 'Select an option...';
352
+ if (processedAttrs.directiveOptions.fngajax) {
353
+ defaultPlaceholder = 'Start typing...'
244
354
  }
245
- // Set up lookup function
246
- addToConversions(processedAttr.info.name, {fngajax: uiSelectHelper.lookupFunc});
247
- // Use the forms-angular API to query the referenced collection
248
- elemScope.ref = processedAttr.info.ref;
249
- scope[processedAttr.info.id + '_options'] = [];
250
- if (multiControl) {
251
- select += '{{$select.selected.text}}';
252
- } else if (processedAttr.options.subschema) {
253
- select += '{{' + attr.model + '.' + processedAttr.info.name.replace(processedAttr.options.subschemaroot, processedAttr.options.subschemaroot + '[$index]') + '.text}}';
254
- } else {
255
- select += '{{' + buildingBlocks.modelString + '.text}}';
355
+ // set up the ui-select directives
356
+ // hack here. buildingBlocks.common will almost certainly contain 'id="xxxx"', but we don't want this because the
357
+ // id will already be in disabledStr. remove it.
358
+ // the right solution here would be to include an option in the params that are passed to buildInputMarkup which
359
+ // specifies whether or not the buildingBlocks that it creates should include the id or not.
360
+ const idIdx = buildingBlocks.common.indexOf('id="');
361
+ if (idIdx > -1) {
362
+ const endIdIdx = buildingBlocks.common.indexOf('"', idIdx + 4);
363
+ if (endIdIdx > -1) {
364
+ buildingBlocks.common = buildingBlocks.common.substring(0, idIdx) + buildingBlocks.common.substring(endIdIdx + 1);
365
+ }
256
366
  }
257
- select += '</ui-select-match>';
258
- select += '<ui-select-choices repeat="option in (' + processedAttr.info.id + '_options) track by $index" ';
259
- select += 'refresh="refreshOptions($select.search, \'' + processedAttr.info.id + '\')" ';
260
- select += 'refresh-delay="100"> ';
261
- select += '<div ng-bind-html="option.text"></div>';
262
- } else if (processedAttr.directiveOptions.deriveoptions) {
263
- if (typeof scope[processedAttr.directiveOptions.deriveoptions] === "function") {
264
- select += optionsFromArray(multiControl, multi, scope[processedAttr.directiveOptions.deriveoptions](), processedAttr.directiveOptions.deriveoptions);
367
+ var select = '<ui-select ' + multiStr + buildingBlocks.common + requiredStr + disabledStr + ' theme="' + theme + '" style="min-width:18em;">'
368
+ select += '<ui-select-match' + allowClearStr + ' placeholder="' + (processedAttrs.info.placeholder || defaultPlaceholder) + '">';
369
+
370
+ if (processedAttrs.directiveOptions.fngajax) {
371
+ // Stash any filters
372
+ if (processedAttrs.directiveOptions.fngajax !== true) {
373
+ elemScope.filter = processedAttrs.directiveOptions.fngajax;
374
+ }
375
+ // if we have a hard-coded ref (processedAttrs.info.ref), forms-angular can perform the lookup conversion for us.
376
+ // where processedAttrs.directiveOptions.refprop is being used instead, the ref is 'variable' - it comes from a property of scope.record, and
377
+ // in this case, we'll need to handle the conversions ourselves.
378
+ addToConversions(processedAttrs.info.name, { fngajax: FngUISelectHelperService.lookupFunc, noconvert: !!processedAttrs.directiveOptions.refprop });
379
+ if (processedAttrs.directiveOptions.refprop) {
380
+ // the property that we'll be getting the ref from may not be populated yet, and might conceivably change at any time, so we
381
+ // need to $watch it. buildingBlocks.modelString will be something like "record.<array>[$index].<field>". replacing <field>
382
+ // with the value of refprop will give us a suitable watch expression.
383
+ const watchStr = buildingBlocks.modelString.substring(0, buildingBlocks.modelString.lastIndexOf(".") + 1) + processedAttrs.directiveOptions.refprop;
384
+ scope.$watch(watchStr, (newValue) => {
385
+ if (newValue && elemScope.ref !== newValue) {
386
+ elemScope.ref = newValue;
387
+ FngUISelectHelperService.doOwnConversion(scope, processedAttrs, elemScope.ref);
388
+ }
389
+ });
390
+ // we also need to re-do the conversion if the user cancels changes. this event does fire on more than just user cancellation,
391
+ // so this is slightly wasteful. but with the caching implemented by uiSelectHelper, this is no big deal.
392
+ scope.$on("fngCancel", () => {
393
+ $timeout(() => {
394
+ if (elemScope.ref) {
395
+ FngUISelectHelperService.doOwnConversion(scope, processedAttrs, elemScope.ref);
396
+ }
397
+ });
398
+ });
399
+ } else {
400
+ elemScope.ref = processedAttrs.info.ref;
401
+ }
402
+ scope[`${uniqueId}_options`] = [];
403
+ if (multiControl) {
404
+ select += '{{$select.selected.text}}';
405
+ } else if (processedAttrs.options.subschema) {
406
+ select += '{{' + attrs.model + '.' + processedAttrs.info.name.replace(processedAttrs.options.subschemaroot, processedAttrs.options.subschemaroot + '[$index]') + '.text}}';
407
+ } else {
408
+ select += '{{' + buildingBlocks.modelString + '.text}}';
409
+ }
410
+ select += '</ui-select-match>';
411
+ select += `<ui-select-choices repeat="option in (${uniqueId}_options) track by $index" `;
412
+ select += `refresh="refreshOptions($select.search, '${uniqueId}')" `;
413
+ select += 'refresh-delay="400"> ';
414
+ select += '<div ng-bind-html="option.text" ng-attr-title="{{ option.text }}"></div>';
415
+ } else if (processedAttrs.directiveOptions.deriveoptions) {
416
+ if (typeof scope[processedAttrs.directiveOptions.deriveoptions] === "function") {
417
+ select += optionsFromArray(multiControl, multi, scope[processedAttrs.directiveOptions.deriveoptions](), processedAttrs.directiveOptions.deriveoptions);
418
+ } else {
419
+ throw new Error("In fng-ui-select " + processedAttrs.directiveOptions.deriveoptions + " is not a function on the scope");
420
+ }
421
+ } else if (processedAttrs.info.options) {
422
+ // Simple case - enumerated options on the form scope
423
+ select += optionsFromArray(multiControl, multi, processedAttrs.info.options);
265
424
  } else {
266
- throw new Error("In fng-ui-select " + processedAttr.directiveOptions.deriveoptions + " is not a function on the scope");
425
+ throw new Error('fng-ui-select has no means of populating select');
267
426
  }
268
- } else if (processedAttr.info.options) {
269
- // Simple case - enumerated options on the form scope
270
- select += optionsFromArray(multiControl, multi, processedAttr.info.options);
271
- } else {
272
- throw new Error('fng-ui-select has no means of populating select');
427
+ select += '</ui-select-choices>';
428
+ select += '</ui-select>';
429
+ return select;
273
430
  }
274
- select += '</ui-select-choices>';
275
- select += '</ui-select>';
276
- return select;
277
- });
278
- scope.content = input + elementHtml;
431
+ );
279
432
  element.append($compile(input + elementHtml)(scope));
280
433
  }
281
434
  }
@@ -14,10 +14,19 @@
14
14
  background-color: rgba(255, 0, 0, 0.10);
15
15
  }
16
16
 
17
- .ui-select-container.ui-select-bootstrap {
18
- top: -4px;
17
+ fng-ui-select div[id*="width-helper"] {
18
+ margin-bottom: 0px!important;
19
19
  }
20
20
 
21
- fng-ui-select > .form-group > fng-link > a.fng-link > label {
22
- margin-top: -5px;
21
+ fng-ui-select div[id*="width-helper"] div {
22
+ min-height: 0px;
23
+ }
24
+
25
+ fng-ui-select div[id*="width-helper"] label.control-label {
26
+ padding-top: 0px!important;
27
+ min-height: 0px!important;
28
+ }
29
+
30
+ .hidden-row {
31
+ display: none;
23
32
  }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const test_1 = require("@playwright/test");
13
+ const unique = new Date().valueOf();
14
+ (0, test_1.test)('Creates a new record with multiple shelves', ({ page }) => __awaiter(void 0, void 0, void 0, function* () {
15
+ yield page.goto('http://localhost:9000/#/k_referencing_self_collection/new');
16
+ yield page.getByLabel('Warehouse Name').fill(`M${unique} Warehouse`);
17
+ yield page.locator('#add_f_shelves_btn').click();
18
+ yield page.locator('#add_f_shelves_btn').click();
19
+ yield page.locator('#add_f_shelves_btn').click();
20
+ yield page.locator('#f_shelves_location_0').click();
21
+ yield page.locator('#f_shelves_location_0').fill('Top');
22
+ yield page.locator('#f_shelves_location_1').click();
23
+ yield page.locator('#f_shelves_location_1').fill('Middle');
24
+ yield page.locator('#f_shelves_location_2').click();
25
+ yield page.locator('#f_shelves_location_2').fill('Bottom');
26
+ yield page.locator('#add_f_items_btn').click();
27
+ yield page.getByLabel('Items Description').click();
28
+ yield page.getByLabel('Items Description').fill('Item 1');
29
+ yield page.getByLabel('Shelf', { exact: true }).selectOption('Middle');
30
+ yield page.locator('#add_f_cleanedShelves').click();
31
+ yield page.locator('#add_f_cleanedShelves').click();
32
+ yield page.locator('#f_cleanedShelves_0').selectOption('Middle');
33
+ yield page.locator('#f_cleanedShelves_1').selectOption('Top');
34
+ yield (0, test_1.expect)(page.locator('#f_cleanedShelves_0')).toContainText('Middle');
35
+ yield (0, test_1.expect)(page.locator('#f_cleanedShelves_0')).toHaveClass(/ng-valid-required/);
36
+ yield page.getByLabel('Favourite Shelf').selectOption('Bottom');
37
+ yield (0, test_1.expect)(page.getByLabel('Favourite Shelf')).toContainText('Bottom');
38
+ yield page.getByRole('button', { name: ' Save' }).click();
39
+ yield (0, test_1.expect)(page.getByRole('button', { name: ' Save' })).toBeDisabled();
40
+ yield (0, test_1.expect)(page.locator('#f_cleanedShelves_0')).toContainText('Middle');
41
+ // await expect(page.locator('#f_cleanedShelves_0')).toHaveClass(/ng-valid-required/); // This currently fails, but has done I think for ages...
42
+ yield (0, test_1.expect)(page.getByLabel('Favourite Shelf')).toContainText('Bottom');
43
+ yield page.goto('http://localhost:9000/#/l_referencing_list_in_other_document/new');
44
+ yield page.getByLabel('Description').click();
45
+ yield page.getByLabel('Description').fill('An item in multi');
46
+ yield page.getByLabel('Select box select').click();
47
+ yield page.getByLabel('Select box', { exact: true }).click();
48
+ yield page.getByLabel('Select box', { exact: true }).fill(`M${unique}`);
49
+ yield page.getByText(`M${unique} Warehouse`).click();
50
+ yield page.getByLabel('Shelf').selectOption('Top');
51
+ }));
52
+ (0, test_1.test)('Creates a new record with a single shelf', ({ page }) => __awaiter(void 0, void 0, void 0, function* () {
53
+ yield page.goto('http://localhost:9000/#/k_referencing_self_collection/new');
54
+ yield page.getByLabel('Warehouse Name').fill(`S${unique} Warehouse`);
55
+ yield page.locator('#add_f_shelves_btn').click();
56
+ yield page.getByLabel('Shelves Location').click();
57
+ yield page.getByLabel('Shelves Location').fill('Only');
58
+ yield page.locator('#add_f_items_btn').click();
59
+ yield page.getByLabel('Items Description').click();
60
+ yield page.getByLabel('Items Description').fill('Item 1');
61
+ yield page.getByLabel('Shelf', { exact: true }).selectOption('Only');
62
+ yield page.locator('#add_f_cleanedShelves').click();
63
+ yield page.getByLabel('Cleaned Shelves').selectOption('Only');
64
+ yield page.getByLabel('Favourite Shelf').selectOption('Only');
65
+ yield page.getByRole('button', { name: ' Save' }).click();
66
+ yield (0, test_1.expect)(page.getByRole('button', { name: ' Save' })).toBeDisabled();
67
+ yield (0, test_1.expect)(page.locator('#f_cleanedShelves_0')).toContainText('Only');
68
+ yield page.goto('http://localhost:9000/#/l_referencing_list_in_other_document/new');
69
+ yield page.getByLabel('Description').fill('Single');
70
+ yield page.getByLabel('Select box select').click();
71
+ yield page.getByLabel('Select box', { exact: true }).click();
72
+ yield page.getByLabel('Select box', { exact: true }).fill(`S${unique}`);
73
+ yield page.getByText(`S${unique} Warehouse`).click();
74
+ yield page.getByLabel('Shelf').selectOption('Only');
75
+ }));