Skip to content

Commit

Permalink
FIO-9527: fixed address component with multiple values
Browse files Browse the repository at this point in the history
  • Loading branch information
roma-formio committed Jan 16, 2025
1 parent 7cbee3b commit aa8260f
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/address/Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
46 changes: 46 additions & 0 deletions test/unit/Address.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
comp2,
comp3,
comp4,
comp5,
} from './fixtures/address';

describe('Address Component', () => {
Expand Down Expand Up @@ -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);
});
});
85 changes: 85 additions & 0 deletions test/unit/fixtures/address/comp5.js
Original file line number Diff line number Diff line change
@@ -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
}
]
}
3 changes: 2 additions & 1 deletion test/unit/fixtures/address/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

0 comments on commit aa8260f

Please sign in to comment.