From a8ce3436a4ffe76ccf892965fa21dc2a467e2d14 Mon Sep 17 00:00:00 2001 From: patelmilanun <20059797+patelmilanun@users.noreply.github.com> Date: Tue, 20 Jun 2023 07:01:31 +0530 Subject: [PATCH] fix: Pasting location coordinates into field of type `GeoPoint` does not work in data browser (#2464) --- .../GeoPointEditor/GeoPointEditor.react.js | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/components/GeoPointEditor/GeoPointEditor.react.js b/src/components/GeoPointEditor/GeoPointEditor.react.js index 597bc529ee..f29e1713b1 100644 --- a/src/components/GeoPointEditor/GeoPointEditor.react.js +++ b/src/components/GeoPointEditor/GeoPointEditor.react.js @@ -106,26 +106,29 @@ export default class GeoPointEditor extends React.Component { let value = e.target.value; if (!validateNumeric(value)) { - var values = value.split(','); - - if (values.length == 2) { - values = values.map(val => val.trim()); - - if (values[0].length > 0 && validateNumeric(values[0])) { - - if (values[1].length <= 0 || !validateNumeric(values[1])) { - this.setState({ latitude: values[0] }); - this.longitudeRef.current.focus(); - this.longitudeRef.current.setSelectionRange(0, String(this.state.longitude).length); - return; - } - - if (validateNumeric(values[1])) { - this.setState({ latitude: values[0] }); - this.setState({ longitude: values[1] }); - this.longitudeRef.current.focus(); - return; - } + const regex = /[[("' ]?(?[0-9.]+)["' ]?,["' ]?(?[0-9.]+)["' )\]]?/; + const match = regex.exec(value); + + if (!match) { + return null; + } + + const values = [match.groups.x, match.groups.y]; + + if (values[0].length > 0 && validateNumeric(values[0])) { + + if (values[1].length <= 0 || !validateNumeric(values[1])) { + this.setState({ latitude: values[0] }); + this.longitudeRef.current.focus(); + this.longitudeRef.current.setSelectionRange(0, String(this.state.longitude).length); + return; + } + + if (validateNumeric(values[1])) { + this.setState({ latitude: values[0] }); + this.setState({ longitude: values[1] }); + this.longitudeRef.current.focus(); + return; } } }