Skip to content

Commit ee62a31

Browse files
authored
Merge pull request #674 from wmde/city-autocomplete-fix
Add model watch to City Autocomplete
2 parents e6ebbec + b182d89 commit ee62a31

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/components/shared/form_fields/CityAutocompleteField.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ watch( city, ( newCity: string ) => {
181181
emit( 'update:modelValue', newCity );
182182
} );
183183
184+
watch( () => props.modelValue, ( newValue: string ) => {
185+
city.value = newValue;
186+
} );
187+
184188
</script>
185189

186190
<style lang="scss">

tests/unit/components/shared/form_fields/CityAutocompleteField.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,14 @@ describe( 'CityAutocompleteField.vue', () => {
261261

262262
expect( wrapper.emitted( 'field-changed' ).length ).toStrictEqual( 1 );
263263
} );
264+
265+
it( 'updates value on model change', async () => {
266+
const wrapper = getWrapper();
267+
268+
expect( wrapper.find<HTMLInputElement>( '#city' ).element.value ).toBe( '' );
269+
270+
await wrapper.setProps( { modelValue: 'Berlin' } );
271+
272+
expect( wrapper.find<HTMLInputElement>( '#city' ).element.value ).toBe( 'Berlin' );
273+
} );
264274
} );

0 commit comments

Comments
 (0)