fng-ui-select 0.12.0-beta.336 → 0.12.0-beta.337

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,7 +1,7 @@
1
1
  {
2
2
  "name": "fng-ui-select",
3
3
  "author": "Mark Chapman <support@forms-angular.org>",
4
- "version": "0.12.0-beta.336",
4
+ "version": "0.12.0-beta.337",
5
5
  "description": "angular-ui-select plugin for forms-angular",
6
6
  "repository": {
7
7
  "type": "git",
@@ -57,6 +57,40 @@
57
57
  clearCache: function () {
58
58
  valueCache = {};
59
59
  },
60
+ // Builds a lookupFunc closure bound to a specific localLookups key. Used for the deriveOptions case
61
+ // instead of the generic lookupFunc below, because deriveOptions can resolve to a different scope
62
+ // array per row (e.g. one "Also willing to work for" picklist per contract row, each with its own
63
+ // leafNodes_N array) - the shared lookupFunc/localLookups keyed by the (row-shared) deriveOptions
64
+ // function name can't distinguish between rows, causing lookups to hit the wrong row's data.
65
+ makeDeriveOptionsLookupFunc: function (lkpName) {
66
+ return function (value, formSchema, cb) {
67
+ if (formSchema.array) {
68
+ const results = value.map((value) => {
69
+ // a value can already have been converted to { id, text } by an earlier run of this same
70
+ // conversion function (forms-angular can re-run conversions - see the comment on
71
+ // $watchCollection("conversions", ...) - so this isn't necessarily the first pass over this
72
+ // field). converting it again would wrap it a second time ({ id: { id, text }, text: "" }),
73
+ // silently corrupting the value, so pass already-converted entries through unchanged.
74
+ if (value && typeof value === "object") {
75
+ return value;
76
+ }
77
+ const obj = localLookups[lkpName].find((test) => test.id === value);
78
+ return { id: value, text: obj ? obj.text : "" };
79
+ });
80
+ cb(formSchema, results);
81
+ if (results.length > 0) {
82
+ setTimeout(function () {
83
+ $rootScope.$digest();
84
+ });
85
+ }
86
+ } else if (typeof value !== "string") {
87
+ cb(formSchema, value); // already converted
88
+ } else {
89
+ const obj = localLookups[lkpName].find((test) => test.id === value);
90
+ cb(formSchema, { id: value, text: obj ? obj.text : "" });
91
+ }
92
+ };
93
+ },
60
94
  lookupFunc: function (value, formSchema, cb) {
61
95
  if (formSchema.array) {
62
96
  if (formSchema.fngUiSelect.deriveOptions) {
@@ -324,8 +358,13 @@
324
358
  function optionsFromArray(multiControl, multi, array, arrayGetter) {
325
359
  var isObjects = scope[array] && (scope[array].isObjects || typeof scope[array][0] === "object");
326
360
  if (isObjects) {
327
- addToConversions(processedAttrs.info.name, { fngajax: FngUISelectHelperService.lookupFunc });
328
- FngUISelectHelperService.addClientLookup(arrayGetter, scope[array]);
361
+ // Key the lookup by the resolved scope array name (e.g. "leafNodes_0"), not by arrayGetter
362
+ // (the deriveOptions function name, which is shared/identical across every row when the same
363
+ // deriveOptions function is used for multiple rows, e.g. one per ng-repeat contract). Using
364
+ // arrayGetter as the key would make every row's conversion overwrite the same cache entry,
365
+ // leaving other rows' lookups resolving against the wrong array and rendering blank text.
366
+ addToConversions(processedAttrs.info.name, { fngajax: FngUISelectHelperService.makeDeriveOptionsLookupFunc(array) });
367
+ FngUISelectHelperService.addClientLookup(array, scope[array]);
329
368
  }
330
369
  var select = '';
331
370
  if (multiControl) {