Skip to content

Commit

Permalink
Ensures Map pin is displayed when loading form with the selected address
Browse files Browse the repository at this point in the history
  • Loading branch information
armine-fliplet committed Dec 4, 2024
1 parent a1603d3 commit d9cbea2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
49 changes: 28 additions & 21 deletions js/components/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@ Fliplet.FormBuilder.field('map', {
this.mapAddressField.change(this.onChange);
},
onChange: function(value) {
if (this.readonly) {
return;
}

if (!value) {
this.mapField.clear();

Expand All @@ -206,8 +202,16 @@ Fliplet.FormBuilder.field('map', {
}

if (this.suggestionSelected && this.lastChosenAutocompleteValue === value.trim()) {
this.value = this.mapField.getTotalAddress();
this.updateAddressSuggestions();
const timeout = this.mapField.getGeocoder() ? 0 : 3000;

setTimeout(() => {
if (this.mapField.getTotalAddress()) {
this.value = this.mapField.getTotalAddress();
}

this.updateAddressSuggestions();
this.$emit('_input', this.name, this.value, false, true);
}, timeout);
} else if (this.mapField.checkIfAddressChangedByDragging()) {
this.updateAddressSuggestions();
this.mapField.checkIfAddressChangedByDragging(false);
Expand All @@ -216,6 +220,7 @@ Fliplet.FormBuilder.field('map', {
latLong: `${this.mapField.get().lat}/${this.mapField.get().lng}`
};
this.suggestionSelected = false;
this.$emit('_input', this.name, this.value, false, true);
} else {
if (suggestions.length === 1 && value.trim() !== '') {
if (this.addressSuggestions.length && this.addressSuggestions[0].label === 'Select location on map') {
Expand All @@ -229,9 +234,8 @@ Fliplet.FormBuilder.field('map', {

this.addressSuggestions = suggestions;
this.suggestionSelected = false;
this.$emit('_input', this.name, this.value, false, true);
}

this.$emit('_input', this.name, this.value, false, true);
});
},
onReset: function() {
Expand Down Expand Up @@ -261,24 +265,27 @@ Fliplet.FormBuilder.field('map', {

if (val.address && val.address.label) {
val = {
address: val.address.label
address: val.address.label,
latLong: null
};
}

if (val.address && !this.suggestionSelected && !this.lastChosenAutocompleteValue && !this.readonly) {
if (val.latLong) {
this.mapAddressField.set(val.address);
this.mapField.set(val.address);
} else {
this.mapAddressField.set(val.address);
}
if (val.address && !this.suggestionSelected && !this.lastChosenAutocompleteValue) {
setTimeout(() => {
if (val.latLong) {
this.mapAddressField.set(val.address);
this.mapField.set(val.address);
} else {
this.mapAddressField.set(val.address);
}

this.suggestionSelected = true;
this.lastChosenAutocompleteValue = val.address;
this.addressSuggestions = [];
this.isSelectOnMapClicked = true;
this.suggestionSelected = true;
this.lastChosenAutocompleteValue = val.address;
this.addressSuggestions = [];
this.isSelectOnMapClicked = true;

return;
return;
}, 1000);
}

if (val.address === '' && !this.readonly && !this.autoCollectUserLocation) {
Expand Down
7 changes: 0 additions & 7 deletions js/libs/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,6 @@ Fliplet().then(function() {
}
}

if (field._type === 'flMap') {
field.value = progress[field.name] || {
address: '',
latLong: null
};
}

setTimeout(function() {
if (progress && !isEditMode) {
var savedValue = progress[field.name];
Expand Down

0 comments on commit d9cbea2

Please sign in to comment.