diff --git a/packages/nc-gui/components/cell/GeoData.vue b/packages/nc-gui/components/cell/GeoData.vue index d2f0bca59c..7c4b3026c9 100644 --- a/packages/nc-gui/components/cell/GeoData.vue +++ b/packages/nc-gui/components/cell/GeoData.vue @@ -63,8 +63,8 @@ const onClickSetCurrentLocation = () => { isLoading.value = true const onSuccess: PositionCallback = (position: GeolocationPosition) => { const crd = position.coords - formState.latitude = `${crd.latitude}` - formState.longitude = `${crd.longitude}` + formState.latitude = `${convertGeoNumberToString(crd.latitude)}` + formState.longitude = `${convertGeoNumberToString(crd.longitude)}` isLoading.value = false } @@ -132,6 +132,20 @@ const isUnderLookup = inject(IsUnderLookupInj, ref(false)) const isCanvasInjected = inject(IsCanvasInjectionInj, false) const isExpandedForm = inject(IsExpandedFormOpenInj, ref(false)) const isGrid = inject(IsGridInj, ref(false)) +const handleBlur = (e: Event) => { + let value = (e.target as any).value as string + const numberBehindDecimal = value.match(/[\.]\d+$/)?.[0] + if (!numberBehindDecimal || numberBehindDecimal.length <= 10) { + return + } + value = convertGeoNumberToString(Number(value)) + if ((e.target as any)!.id === identifier.value.latitude) { + formState.latitude = value + } else if ((e.target as any)!.id === identifier.value.longitude) { + formState.longitude = value + } +} + onMounted(() => { if (!isUnderLookup.value && isCanvasInjected && !isExpandedForm.value && isGrid.value) { forcedNextTick(() => { @@ -191,6 +205,7 @@ watch( :min="-90" required :max="90" + @blur="handleBlur" @keydown.stop @selectstart.capture.stop @mousedown.stop @@ -208,6 +223,7 @@ watch( required :min="-180" :max="180" + @blur="handleBlur" @keydown.stop @selectstart.capture.stop @mousedown.stop diff --git a/packages/nc-gui/composables/useMultiSelect/convertCellData.ts b/packages/nc-gui/composables/useMultiSelect/convertCellData.ts index d24458ee3b..c150209fd0 100644 --- a/packages/nc-gui/composables/useMultiSelect/convertCellData.ts +++ b/packages/nc-gui/composables/useMultiSelect/convertCellData.ts @@ -352,7 +352,7 @@ export default function convertCellData( .map((k) => k.trim()) if (geoValue.length === 2) { if (!isNaN(Number(geoValue[0])) && !isNaN(Number(geoValue[1]))) { - return geoValue.map((k) => Number(k).toFixed(10).replace(/[0]+$/, '')).join(';') + return geoValue.map((k) => convertGeoNumberToString(Number(k))).join(';') } } throw new SilentTypeConversionError() diff --git a/packages/nc-gui/utils/geoDataUtils.ts b/packages/nc-gui/utils/geoDataUtils.ts index a914804995..db54cbaf7c 100644 --- a/packages/nc-gui/utils/geoDataUtils.ts +++ b/packages/nc-gui/utils/geoDataUtils.ts @@ -1,3 +1,5 @@ -const latLongToJoinedString = (lat: number, long: number) => `${lat.toFixed(7)};${long.toFixed(7)}` +export const convertGeoNumberToString = (val: number) => { + return val.toFixed(10).replace(/[\.]0+$|([\.][^0]*)[0]+$/, '$1') +} -export { latLongToJoinedString } +export const latLongToJoinedString = (lat: number, long: number) => [lat, long].map((k) => convertGeoNumberToString(k)).join(';')