diff --git a/src/components/address/Address.js b/src/components/address/Address.js index 3fe44cf771..5fedf16e19 100644 --- a/src/components/address/Address.js +++ b/src/components/address/Address.js @@ -264,7 +264,7 @@ export default class AddressComponent extends ContainerComponent { } get dataValue() { - const resultValue = _.get(this._data, this.component.path); + const resultValue = _.get(this._data, this.path); if (!_.isArray(resultValue) && this.component.multiple) { return [resultValue] } diff --git a/test/unit/Address.unit.js b/test/unit/Address.unit.js index 123e92b619..bd68c76468 100644 --- a/test/unit/Address.unit.js +++ b/test/unit/Address.unit.js @@ -8,6 +8,7 @@ import { comp2, comp3, comp4, + comp5, } from './fixtures/address'; describe('Address Component', () => { @@ -230,4 +231,49 @@ describe('Address Component', () => { }, 300); }); }); + + it('Should build an address component with multiple values and set value', (done) => { + const element = document.createElement('div'); + + Formio.createForm(element, _.cloneDeep(comp5)).then(form => { + const address = form.getComponent('address'); + assert.equal(!!address.provider, true); + assert.deepEqual(address.dataValue, [{}]); + address.addRow(); + assert.deepEqual(address.dataValue, [{}, {}]); + + const value = [{ + place_id: 258689701, + licence: 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright', + osm_type: 'relation', + osm_id: 65606, + lat: '51.4893335', + lon: '-0.14405508452768728', + class: 'boundary', + type: 'ceremonial', + place_rank: 25, + importance: 0.8820890292539882, + addresstype: 'city', + name: 'London', + display_name: 'London, Greater London, England, United Kingdom', + address: { + city: 'London', + state_district: 'Greater London', + state: 'England', + 'ISO3166-2-lvl4': 'GB-ENG', + country: 'United Kingdom', + country_code: 'gb' + }, + boundingbox: [ + '51.2867601', + '51.6918741', + '-0.5103751', + '0.3340155' + ] + }, {}]; + address.setValue(value); + assert.deepEqual(address.dataValue, value); + done(); + }).catch(done); + }); }); diff --git a/test/unit/fixtures/address/comp5.js b/test/unit/fixtures/address/comp5.js new file mode 100644 index 0000000000..9dec701191 --- /dev/null +++ b/test/unit/fixtures/address/comp5.js @@ -0,0 +1,85 @@ +export default { + type: 'form', + display: 'form', + title: 'FIO-9527', + name: 'fio9527', + path: 'fio9527', + components: [ + { + label: 'Address', + tableView: false, + multiple: true, + provider: 'nominatim', + validateWhenHidden: false, + key: 'address', + providerOptions: { + params: { + autocompleteOptions: {} + } + }, + type: 'address', + input: true, + components: [ + { + label: 'Address 1', + tableView: false, + key: 'address1', + type: 'textfield', + input: true, + customConditional: "show = _.get(instance, 'parent.manualMode', false);" + }, + { + label: 'Address 2', + tableView: false, + key: 'address2', + type: 'textfield', + input: true, + customConditional: "show = _.get(instance, 'parent.manualMode', false);" + }, + { + label: 'City', + tableView: false, + key: 'city', + type: 'textfield', + input: true, + customConditional: "show = _.get(instance, 'parent.manualMode', false);" + }, + { + label: 'State', + tableView: false, + key: 'state', + type: 'textfield', + input: true, + customConditional: "show = _.get(instance, 'parent.manualMode', false);" + }, + { + label: 'Country', + tableView: false, + key: 'country', + type: 'textfield', + input: true, + customConditional: "show = _.get(instance, 'parent.manualMode', false);" + }, + { + label: 'Zip Code', + tableView: false, + key: 'zip', + type: 'textfield', + input: true, + customConditional: "show = _.get(instance, 'parent.manualMode', false);" + } + ], + defaultValue: [ + {} + ] + }, + { + type: 'button', + label: 'Submit', + key: 'submit', + disableOnInvalid: true, + input: true, + tableView: false + } + ] +} diff --git a/test/unit/fixtures/address/index.js b/test/unit/fixtures/address/index.js index f1a58d4b03..e6e320dd66 100644 --- a/test/unit/fixtures/address/index.js +++ b/test/unit/fixtures/address/index.js @@ -2,4 +2,5 @@ import comp1 from './comp1'; import comp2 from './comp2'; import comp3 from './comp3'; import comp4 from './comp4'; -export { comp1, comp2, comp3, comp4 }; +import comp5 from './comp5'; +export { comp1, comp2, comp3, comp4, comp5 };