Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/DEV-230 #697

Merged
merged 12 commits into from
Dec 13, 2024
49 changes: 27 additions & 22 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();
}
dwfliplet marked this conversation as resolved.
Show resolved Hide resolved
dwfliplet marked this conversation as resolved.
Show resolved Hide resolved

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,25 @@ 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);
}

this.suggestionSelected = true;
this.lastChosenAutocompleteValue = val.address;
this.addressSuggestions = [];
this.isSelectOnMapClicked = true;
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);
}

return;
this.suggestionSelected = true;
this.lastChosenAutocompleteValue = val.address;
this.addressSuggestions = [];
this.isSelectOnMapClicked = true;
}, 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
Loading