@formio/js 5.0.0-dev.5936.905c79f → 5.0.0-dev.5940.cf4089b

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.
@@ -27,7 +27,6 @@ export default class RadioComponent extends ListComponent {
27
27
  itemsLoadedResolve: ((value: any) => void) | undefined;
28
28
  optionsLoaded: boolean | undefined;
29
29
  loadedOptions: any[] | undefined;
30
- valuesMap: Map<any, any> | undefined;
31
30
  beforeSubmit(): Promise<any>;
32
31
  render(): import("../_classes/field/Field").default;
33
32
  attach(element: any): Promise<void>;
@@ -36,13 +35,10 @@ export default class RadioComponent extends ListComponent {
36
35
  validateValueAvailability(setting: any, value: any): boolean;
37
36
  getValueAsString(value: any, options?: {}): any;
38
37
  setValueAt(index: any, value: any): void;
39
- prepareValue(item: any, options?: {}): any;
40
- getValueByInput(input: any): any;
41
38
  loadItems(url: any, search: any, headers: any, options: any, method: any, body: any): void;
42
39
  loadItemsFromMetadata(): void;
43
40
  setItems(items: any): void;
44
41
  setSelectedClasses(): void;
45
- setMetadata(value: any): void;
46
42
  updateValue(value: any, flags: any): boolean;
47
43
  currentValue: any;
48
44
  }
@@ -7,7 +7,6 @@ const lodash_1 = __importDefault(require("lodash"));
7
7
  const ListComponent_1 = __importDefault(require("../_classes/list/ListComponent"));
8
8
  const Formio_1 = require("../../Formio");
9
9
  const utils_1 = require("../../utils/utils");
10
- const uuid_1 = require("uuid");
11
10
  class RadioComponent extends ListComponent_1.default {
12
11
  static schema(...extend) {
13
12
  return ListComponent_1.default.schema({
@@ -143,7 +142,6 @@ class RadioComponent extends ListComponent_1.default {
143
142
  });
144
143
  this.optionsLoaded = !this.component.dataSrc || this.component.dataSrc === 'values';
145
144
  this.loadedOptions = [];
146
- this.valuesMap = new Map();
147
145
  if (!this.visible) {
148
146
  this.itemsLoadedResolve();
149
147
  }
@@ -183,12 +181,9 @@ class RadioComponent extends ListComponent_1.default {
183
181
  if (!lodash_1.default.isString(this.dataValue)) {
184
182
  dataValue = lodash_1.default.toString(this.dataValue);
185
183
  }
186
- if (this.isSelectURL) {
187
- const valueKey = this.loadedOptions[index].value;
188
- const optionValue = this.valuesMap.has(valueKey)
189
- ? this.valuesMap.get(valueKey)
190
- : valueKey;
191
- input.checked = lodash_1.default.isEqual(this.normalizeValue(optionValue), this.dataValue);
184
+ if (this.isSelectURL && lodash_1.default.isObject(this.loadedOptions[index].value)) {
185
+ const optionValue = this.component.dataType === 'string' ? JSON.stringify(this.loadedOptions[index].value) : this.loadedOptions[index].value;
186
+ input.checked = lodash_1.default.isEqual(optionValue, this.dataValue);
192
187
  }
193
188
  else {
194
189
  input.checked = (dataValue === input.value && (input.value || this.component.dataSrc !== 'url'));
@@ -225,14 +220,9 @@ class RadioComponent extends ListComponent_1.default {
225
220
  let value = this.component.inputType === 'checkbox' ? '' : this.dataValue;
226
221
  this.refs.input.forEach((input, index) => {
227
222
  if (input.checked) {
228
- if (!this.isSelectURL) {
229
- value = input.value;
230
- return;
231
- }
232
- const optionValue = this.loadedOptions[index].value;
233
- value = this.valuesMap.has(optionValue)
234
- ? this.valuesMap.get(optionValue)
235
- : optionValue;
223
+ value = (this.isSelectURL && lodash_1.default.isObject(this.loadedOptions[index].value)) ?
224
+ this.loadedOptions[index].value :
225
+ input.value;
236
226
  }
237
227
  });
238
228
  return value;
@@ -276,8 +266,8 @@ class RadioComponent extends ListComponent_1.default {
276
266
  }
277
267
  setValueAt(index, value) {
278
268
  if (this.refs.input && this.refs.input[index] && value !== null && value !== undefined) {
279
- const inputValue = this.getValueByInput(this.refs.input[index]);
280
- this.refs.input[index].checked = lodash_1.default.isEqual(inputValue, value);
269
+ const inputValue = this.refs.input[index].value;
270
+ this.refs.input[index].checked = (inputValue === value.toString());
281
271
  }
282
272
  }
283
273
  get shouldLoad() {
@@ -287,23 +277,6 @@ class RadioComponent extends ListComponent_1.default {
287
277
  }
288
278
  return super.shouldLoad;
289
279
  }
290
- prepareValue(item, options = {}) {
291
- const value = this.component.valueProperty && !options.skipValueProperty
292
- ? lodash_1.default.get(item, this.component.valueProperty)
293
- : item;
294
- if (this.component.type === 'radio' && typeof value !== 'string') {
295
- const uuid = (0, uuid_1.v4)();
296
- this.valuesMap.set(uuid, value);
297
- return uuid;
298
- }
299
- return value;
300
- }
301
- getValueByInput(input) {
302
- const inputValue = input.value;
303
- return this.valuesMap.has(inputValue)
304
- ? this.valuesMap.get(inputValue)
305
- : inputValue;
306
- }
307
280
  loadItems(url, search, headers, options, method, body) {
308
281
  if (this.optionsLoaded) {
309
282
  this.itemsLoadedResolve();
@@ -354,7 +327,7 @@ class RadioComponent extends ListComponent_1.default {
354
327
  label: this.itemTemplate(item)
355
328
  };
356
329
  if (lodash_1.default.isEqual(item, this.selectData || lodash_1.default.pick(this.dataValue, lodash_1.default.keys(item)))) {
357
- this.loadedOptions[i].value = this.prepareValue(this.dataValue, { skipValueProperty: true });
330
+ this.loadedOptions[i].value = this.dataValue;
358
331
  }
359
332
  });
360
333
  this.optionsLoaded = true;
@@ -364,15 +337,12 @@ class RadioComponent extends ListComponent_1.default {
364
337
  const listData = [];
365
338
  items === null || items === void 0 ? void 0 : items.forEach((item, i) => {
366
339
  const valueAtProperty = lodash_1.default.get(item, this.component.valueProperty);
367
- const value = this.prepareValue(item);
368
- const label = this.component.valueProperty
369
- ? this.itemTemplate(item, valueAtProperty, i)
370
- : this.itemTemplate(item, item, i);
371
- this.loadedOptions[i] = { label, value };
372
- listData.push(this.templateData[i]);
373
- if (this.valuesMap.has(value)) {
374
- this.templateData[value] = this.templateData[i];
375
- }
340
+ this.loadedOptions[i] = {
341
+ value: this.component.valueProperty ? valueAtProperty : item,
342
+ label: this.component.valueProperty ? this.itemTemplate(item, valueAtProperty) : this.itemTemplate(item, item, i)
343
+ };
344
+ listData.push(this.templateData[this.component.valueProperty ? valueAtProperty : i]);
345
+ const value = this.loadedOptions[i].value;
376
346
  if (!this.isRadio && (lodash_1.default.isObject(value) || lodash_1.default.isBoolean(value) || lodash_1.default.isUndefined(value))) {
377
347
  this.loadedOptions[i].invalid = true;
378
348
  }
@@ -395,9 +365,7 @@ class RadioComponent extends ListComponent_1.default {
395
365
  const value = this.dataValue;
396
366
  this.refs.wrapper.forEach((wrapper, index) => {
397
367
  const input = this.refs.input[index];
398
- const checked = (input.type === 'checkbox')
399
- ? value[input.value] || input.checked
400
- : lodash_1.default.isEqual(this.normalizeValue(this.getValueByInput(input)), value);
368
+ const checked = (input.type === 'checkbox') ? value[input.value] || input.checked : (input.value.toString() === value.toString());
401
369
  if (checked) {
402
370
  //add class to container when selected
403
371
  this.addClass(wrapper, this.optionSelectedClass);
@@ -411,25 +379,10 @@ class RadioComponent extends ListComponent_1.default {
411
379
  });
412
380
  }
413
381
  }
414
- setMetadata(value) {
415
- let key = value;
416
- if (typeof value !== 'string') {
417
- const checkedInput = Array.prototype.find.call(this.refs.input, (input => input.type === 'radio' && input.getAttribute('checked')));
418
- key = (checkedInput === null || checkedInput === void 0 ? void 0 : checkedInput.value) || key;
419
- }
420
- if (this.isSelectURL && this.templateData && this.templateData[key]) {
421
- const submission = this.root.submission;
422
- if (!submission.metadata.selectData) {
423
- submission.metadata.selectData = {};
424
- }
425
- lodash_1.default.set(submission.metadata.selectData, this.path, this.templateData[key]);
426
- }
427
- }
428
382
  updateValue(value, flags) {
429
383
  const changed = super.updateValue(value, flags);
430
384
  if (changed) {
431
385
  this.setSelectedClasses();
432
- this.setMetadata(this.dataValue);
433
386
  }
434
387
  if (!flags || !flags.modified || !this.isRadio) {
435
388
  if (changed) {
@@ -485,10 +438,14 @@ class RadioComponent extends ListComponent_1.default {
485
438
  value = !(!value || value.toString() === 'false');
486
439
  break;
487
440
  }
441
+ if (this.isSelectURL && this.templateData && this.templateData[value]) {
442
+ const submission = this.root.submission;
443
+ if (!submission.metadata.selectData) {
444
+ submission.metadata.selectData = {};
445
+ }
446
+ lodash_1.default.set(submission.metadata.selectData, this.path, this.templateData[value]);
447
+ }
488
448
  return super.normalizeValue(value);
489
449
  }
490
- isSingleInputValue() {
491
- return true;
492
- }
493
450
  }
494
451
  exports.default = RadioComponent;
@@ -73,6 +73,7 @@ function registerModule(mod, defaultFn = null, options = {}) {
73
73
  case 'templates':
74
74
  for (const framework of Object.keys(mod.templates)) {
75
75
  Formio_1.Formio.Templates.extendTemplate(framework, mod.templates[framework]);
76
+ Formio_1.Formio.Templates.defaultTemplates = lodash_1.default.defaults(mod.templates[framework], Formio_1.Formio.Templates.defaultTemplates);
76
77
  }
77
78
  if (mod.templates[current]) {
78
79
  Formio_1.Formio.Templates.current = mod.templates[current];
@@ -27,7 +27,6 @@ export default class RadioComponent extends ListComponent {
27
27
  itemsLoadedResolve: ((value: any) => void) | undefined;
28
28
  optionsLoaded: boolean | undefined;
29
29
  loadedOptions: any[] | undefined;
30
- valuesMap: Map<any, any> | undefined;
31
30
  beforeSubmit(): Promise<any>;
32
31
  render(): import("../_classes/field/Field").default;
33
32
  attach(element: any): Promise<void>;
@@ -36,13 +35,10 @@ export default class RadioComponent extends ListComponent {
36
35
  validateValueAvailability(setting: any, value: any): boolean;
37
36
  getValueAsString(value: any, options?: {}): any;
38
37
  setValueAt(index: any, value: any): void;
39
- prepareValue(item: any, options?: {}): any;
40
- getValueByInput(input: any): any;
41
38
  loadItems(url: any, search: any, headers: any, options: any, method: any, body: any): void;
42
39
  loadItemsFromMetadata(): void;
43
40
  setItems(items: any): void;
44
41
  setSelectedClasses(): void;
45
- setMetadata(value: any): void;
46
42
  updateValue(value: any, flags: any): boolean;
47
43
  currentValue: any;
48
44
  }
@@ -2,7 +2,6 @@ import _ from 'lodash';
2
2
  import ListComponent from '../_classes/list/ListComponent';
3
3
  import { Formio } from '../../Formio';
4
4
  import { boolValue, componentValueTypes, getComponentSavedTypes } from '../../utils/utils';
5
- import { v4 as uuidv4 } from 'uuid';
6
5
  export default class RadioComponent extends ListComponent {
7
6
  static schema(...extend) {
8
7
  return ListComponent.schema({
@@ -143,7 +142,6 @@ export default class RadioComponent extends ListComponent {
143
142
  });
144
143
  this.optionsLoaded = !this.component.dataSrc || this.component.dataSrc === 'values';
145
144
  this.loadedOptions = [];
146
- this.valuesMap = new Map();
147
145
  if (!this.visible) {
148
146
  this.itemsLoadedResolve();
149
147
  }
@@ -183,12 +181,9 @@ export default class RadioComponent extends ListComponent {
183
181
  if (!_.isString(this.dataValue)) {
184
182
  dataValue = _.toString(this.dataValue);
185
183
  }
186
- if (this.isSelectURL) {
187
- const valueKey = this.loadedOptions[index].value;
188
- const optionValue = this.valuesMap.has(valueKey)
189
- ? this.valuesMap.get(valueKey)
190
- : valueKey;
191
- input.checked = _.isEqual(this.normalizeValue(optionValue), this.dataValue);
184
+ if (this.isSelectURL && _.isObject(this.loadedOptions[index].value)) {
185
+ const optionValue = this.component.dataType === 'string' ? JSON.stringify(this.loadedOptions[index].value) : this.loadedOptions[index].value;
186
+ input.checked = _.isEqual(optionValue, this.dataValue);
192
187
  }
193
188
  else {
194
189
  input.checked = (dataValue === input.value && (input.value || this.component.dataSrc !== 'url'));
@@ -225,14 +220,9 @@ export default class RadioComponent extends ListComponent {
225
220
  let value = this.component.inputType === 'checkbox' ? '' : this.dataValue;
226
221
  this.refs.input.forEach((input, index) => {
227
222
  if (input.checked) {
228
- if (!this.isSelectURL) {
229
- value = input.value;
230
- return;
231
- }
232
- const optionValue = this.loadedOptions[index].value;
233
- value = this.valuesMap.has(optionValue)
234
- ? this.valuesMap.get(optionValue)
235
- : optionValue;
223
+ value = (this.isSelectURL && _.isObject(this.loadedOptions[index].value)) ?
224
+ this.loadedOptions[index].value :
225
+ input.value;
236
226
  }
237
227
  });
238
228
  return value;
@@ -276,8 +266,8 @@ export default class RadioComponent extends ListComponent {
276
266
  }
277
267
  setValueAt(index, value) {
278
268
  if (this.refs.input && this.refs.input[index] && value !== null && value !== undefined) {
279
- const inputValue = this.getValueByInput(this.refs.input[index]);
280
- this.refs.input[index].checked = _.isEqual(inputValue, value);
269
+ const inputValue = this.refs.input[index].value;
270
+ this.refs.input[index].checked = (inputValue === value.toString());
281
271
  }
282
272
  }
283
273
  get shouldLoad() {
@@ -287,23 +277,6 @@ export default class RadioComponent extends ListComponent {
287
277
  }
288
278
  return super.shouldLoad;
289
279
  }
290
- prepareValue(item, options = {}) {
291
- const value = this.component.valueProperty && !options.skipValueProperty
292
- ? _.get(item, this.component.valueProperty)
293
- : item;
294
- if (this.component.type === 'radio' && typeof value !== 'string') {
295
- const uuid = uuidv4();
296
- this.valuesMap.set(uuid, value);
297
- return uuid;
298
- }
299
- return value;
300
- }
301
- getValueByInput(input) {
302
- const inputValue = input.value;
303
- return this.valuesMap.has(inputValue)
304
- ? this.valuesMap.get(inputValue)
305
- : inputValue;
306
- }
307
280
  loadItems(url, search, headers, options, method, body) {
308
281
  if (this.optionsLoaded) {
309
282
  this.itemsLoadedResolve();
@@ -354,7 +327,7 @@ export default class RadioComponent extends ListComponent {
354
327
  label: this.itemTemplate(item)
355
328
  };
356
329
  if (_.isEqual(item, this.selectData || _.pick(this.dataValue, _.keys(item)))) {
357
- this.loadedOptions[i].value = this.prepareValue(this.dataValue, { skipValueProperty: true });
330
+ this.loadedOptions[i].value = this.dataValue;
358
331
  }
359
332
  });
360
333
  this.optionsLoaded = true;
@@ -364,15 +337,12 @@ export default class RadioComponent extends ListComponent {
364
337
  const listData = [];
365
338
  items?.forEach((item, i) => {
366
339
  const valueAtProperty = _.get(item, this.component.valueProperty);
367
- const value = this.prepareValue(item);
368
- const label = this.component.valueProperty
369
- ? this.itemTemplate(item, valueAtProperty, i)
370
- : this.itemTemplate(item, item, i);
371
- this.loadedOptions[i] = { label, value };
372
- listData.push(this.templateData[i]);
373
- if (this.valuesMap.has(value)) {
374
- this.templateData[value] = this.templateData[i];
375
- }
340
+ this.loadedOptions[i] = {
341
+ value: this.component.valueProperty ? valueAtProperty : item,
342
+ label: this.component.valueProperty ? this.itemTemplate(item, valueAtProperty) : this.itemTemplate(item, item, i)
343
+ };
344
+ listData.push(this.templateData[this.component.valueProperty ? valueAtProperty : i]);
345
+ const value = this.loadedOptions[i].value;
376
346
  if (!this.isRadio && (_.isObject(value) || _.isBoolean(value) || _.isUndefined(value))) {
377
347
  this.loadedOptions[i].invalid = true;
378
348
  }
@@ -395,9 +365,7 @@ export default class RadioComponent extends ListComponent {
395
365
  const value = this.dataValue;
396
366
  this.refs.wrapper.forEach((wrapper, index) => {
397
367
  const input = this.refs.input[index];
398
- const checked = (input.type === 'checkbox')
399
- ? value[input.value] || input.checked
400
- : _.isEqual(this.normalizeValue(this.getValueByInput(input)), value);
368
+ const checked = (input.type === 'checkbox') ? value[input.value] || input.checked : (input.value.toString() === value.toString());
401
369
  if (checked) {
402
370
  //add class to container when selected
403
371
  this.addClass(wrapper, this.optionSelectedClass);
@@ -411,25 +379,10 @@ export default class RadioComponent extends ListComponent {
411
379
  });
412
380
  }
413
381
  }
414
- setMetadata(value) {
415
- let key = value;
416
- if (typeof value !== 'string') {
417
- const checkedInput = Array.prototype.find.call(this.refs.input, (input => input.type === 'radio' && input.getAttribute('checked')));
418
- key = checkedInput?.value || key;
419
- }
420
- if (this.isSelectURL && this.templateData && this.templateData[key]) {
421
- const submission = this.root.submission;
422
- if (!submission.metadata.selectData) {
423
- submission.metadata.selectData = {};
424
- }
425
- _.set(submission.metadata.selectData, this.path, this.templateData[key]);
426
- }
427
- }
428
382
  updateValue(value, flags) {
429
383
  const changed = super.updateValue(value, flags);
430
384
  if (changed) {
431
385
  this.setSelectedClasses();
432
- this.setMetadata(this.dataValue);
433
386
  }
434
387
  if (!flags || !flags.modified || !this.isRadio) {
435
388
  if (changed) {
@@ -485,9 +438,13 @@ export default class RadioComponent extends ListComponent {
485
438
  value = !(!value || value.toString() === 'false');
486
439
  break;
487
440
  }
441
+ if (this.isSelectURL && this.templateData && this.templateData[value]) {
442
+ const submission = this.root.submission;
443
+ if (!submission.metadata.selectData) {
444
+ submission.metadata.selectData = {};
445
+ }
446
+ _.set(submission.metadata.selectData, this.path, this.templateData[value]);
447
+ }
488
448
  return super.normalizeValue(value);
489
449
  }
490
- isSingleInputValue() {
491
- return true;
492
- }
493
450
  }
@@ -56,6 +56,7 @@ export function registerModule(mod, defaultFn = null, options = {}) {
56
56
  case 'templates':
57
57
  for (const framework of Object.keys(mod.templates)) {
58
58
  Formio.Templates.extendTemplate(framework, mod.templates[framework]);
59
+ Formio.Templates.defaultTemplates = _.defaults(mod.templates[framework], Formio.Templates.defaultTemplates);
59
60
  }
60
61
  if (mod.templates[current]) {
61
62
  Formio.Templates.current = mod.templates[current];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.0.0-dev.5936.905c79f",
3
+ "version": "5.0.0-dev.5940.cf4089b",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {