|
74 | 74 | const promises = value.map((value) => { |
75 | 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 | 76 | if (!id) { |
77 | | - return $q.resolve({ data: { list: ""} }); // nothing to convert |
| 77 | + return $q.resolve({ data: { list: "" } }); // nothing to convert |
78 | 78 | } else if (valueCache[id]) { |
79 | | - return $q.resolve({ data: { list: valueCache[id] }}); // already cached |
| 79 | + return $q.resolve({ data: { list: valueCache[id] } }); // already cached |
80 | 80 | } else { |
81 | 81 | return SubmissionsService.getListAttributes(formSchema.ref, id); // need to look it up |
82 | 82 | } |
|
106 | 106 | useCacheOrLookItUp(formSchema.ref, value, (text) => { cb(formSchema, { id: value, text }) }); |
107 | 107 | } |
108 | 108 | }, |
109 | | - doOwnConversion: function(scope, processedAttrs, ref) { |
| 109 | + doOwnConversion: function (scope, processedAttrs, ref) { |
110 | 110 | var id = RecordHandlerService.getData(scope.record, processedAttrs.info.name, scope.$index); |
111 | 111 | if (id) { |
112 | 112 | id = id.id || id; // in case it's already been converted |
|
162 | 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 | 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 | 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; |
| 165 | + var record = JSON.stringify($scope.record).length >= (4 * 1024) ? { _id: $scope.record._id } : $scope.record; |
166 | 166 | // Custom URL |
167 | 167 | promise = $http({ |
168 | 168 | method: 'GET', |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | }) |
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 | | - }); |
| 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 | + }); |
203 | 203 | } |
204 | 204 | } else { |
205 | 205 | throw new Error('Could not find uiSelect element for ' + id); |
|
224 | 224 | function addToConversions(path, options) { |
225 | 225 | if (Object.keys(options).length > 0) { |
226 | 226 | var keys = path.split('.'); |
227 | | - if (!scope.conversions) { |
228 | | - 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 = {}; |
229 | 236 | } |
230 | | - var target = scope.conversions; |
| 237 | + var target = conversionScope.conversions; |
231 | 238 | for (var i = 0; i < keys.length; i++) { |
232 | 239 | var thisKey = keys[i]; |
233 | 240 | target[thisKey] = target[thisKey] || {}; |
234 | 241 | target = target[thisKey]; |
235 | 242 | } |
236 | 243 | angular.extend(target, options); |
| 244 | + conversionScope.conversionsModified = true; |
237 | 245 | } |
238 | 246 | } |
239 | 247 |
|
240 | 248 | const processedAttrs = PluginHelperService.extractFromAttr(attrs, 'fngUiSelect', scope); |
241 | 249 | const id = processedAttrs.info.id; |
242 | 250 | const uniqueId = scope.$index !== undefined ? processedAttrs.info.id + "_" + scope.$index : id; |
243 | | - const elemScope = angular.extend({selectId: uniqueId}, processedAttrs.directiveOptions); |
| 251 | + const elemScope = angular.extend({ selectId: uniqueId }, processedAttrs.directiveOptions); |
244 | 252 | const multi = processedAttrs.info.array; |
245 | 253 | let elementHtml; |
246 | 254 | let input = ''; |
|
259 | 267 | if (angular.module('ngAnimate')) { |
260 | 268 | theme = 'select2'; |
261 | 269 | } |
262 | | - } catch(e) { |
| 270 | + } catch (e) { |
263 | 271 | ; // module not present, so bootstrap theme will work |
264 | 272 | } |
265 | 273 | } |
|
316 | 324 | function optionsFromArray(multiControl, multi, array, arrayGetter) { |
317 | 325 | var isObjects = scope[array] && (scope[array].isObjects || typeof scope[array][0] === "object"); |
318 | 326 | if (isObjects) { |
319 | | - addToConversions(processedAttrs.info.name, {fngajax: FngUISelectHelperService.lookupFunc}); |
| 327 | + addToConversions(processedAttrs.info.name, { fngajax: FngUISelectHelperService.lookupFunc }); |
320 | 328 | FngUISelectHelperService.addClientLookup(arrayGetter, scope[array]); |
321 | 329 | } |
322 | 330 | var select = ''; |
|
351 | 359 | // specifies whether or not the buildingBlocks that it creates should include the id or not. |
352 | 360 | const idIdx = buildingBlocks.common.indexOf('id="'); |
353 | 361 | if (idIdx > -1) { |
354 | | - const endIdIdx = buildingBlocks.common.indexOf('"', idIdx+4); |
| 362 | + const endIdIdx = buildingBlocks.common.indexOf('"', idIdx + 4); |
355 | 363 | if (endIdIdx > -1) { |
356 | 364 | buildingBlocks.common = buildingBlocks.common.substring(0, idIdx) + buildingBlocks.common.substring(endIdIdx + 1); |
357 | 365 | } |
|
367 | 375 | // if we have a hard-coded ref (processedAttrs.info.ref), forms-angular can perform the lookup conversion for us. |
368 | 376 | // where processedAttrs.directiveOptions.refprop is being used instead, the ref is 'variable' - it comes from a property of scope.record, and |
369 | 377 | // in this case, we'll need to handle the conversions ourselves. |
370 | | - addToConversions(processedAttrs.info.name, {fngajax: FngUISelectHelperService.lookupFunc, noconvert: !!processedAttrs.directiveOptions.refprop}); |
| 378 | + addToConversions(processedAttrs.info.name, { fngajax: FngUISelectHelperService.lookupFunc, noconvert: !!processedAttrs.directiveOptions.refprop }); |
371 | 379 | if (processedAttrs.directiveOptions.refprop) { |
372 | 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 |
373 | 381 | // need to $watch it. buildingBlocks.modelString will be something like "record.<array>[$index].<field>". replacing <field> |
|
390 | 398 | }); |
391 | 399 | } else { |
392 | 400 | elemScope.ref = processedAttrs.info.ref; |
393 | | - } |
| 401 | + } |
394 | 402 | scope[`${uniqueId}_options`] = []; |
395 | 403 | if (multiControl) { |
396 | 404 | select += '{{$select.selected.text}}'; |
|
420 | 428 | select += '</ui-select>'; |
421 | 429 | return select; |
422 | 430 | } |
423 | | - ); |
| 431 | + ); |
424 | 432 | element.append($compile(input + elementHtml)(scope)); |
425 | 433 | } |
426 | 434 | } |
|
0 commit comments