Skip to content

Commit a8ce343

Browse files
authored
fix: Pasting location coordinates into field of type GeoPoint does not work in data browser (#2464)
1 parent 5293640 commit a8ce343

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

src/components/GeoPointEditor/GeoPointEditor.react.js

+23-20
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,29 @@ export default class GeoPointEditor extends React.Component {
106106
let value = e.target.value;
107107

108108
if (!validateNumeric(value)) {
109-
var values = value.split(',');
110-
111-
if (values.length == 2) {
112-
values = values.map(val => val.trim());
113-
114-
if (values[0].length > 0 && validateNumeric(values[0])) {
115-
116-
if (values[1].length <= 0 || !validateNumeric(values[1])) {
117-
this.setState({ latitude: values[0] });
118-
this.longitudeRef.current.focus();
119-
this.longitudeRef.current.setSelectionRange(0, String(this.state.longitude).length);
120-
return;
121-
}
122-
123-
if (validateNumeric(values[1])) {
124-
this.setState({ latitude: values[0] });
125-
this.setState({ longitude: values[1] });
126-
this.longitudeRef.current.focus();
127-
return;
128-
}
109+
const regex = /[[("' ]?(?<x>[0-9.]+)["' ]?,["' ]?(?<y>[0-9.]+)["' )\]]?/;
110+
const match = regex.exec(value);
111+
112+
if (!match) {
113+
return null;
114+
}
115+
116+
const values = [match.groups.x, match.groups.y];
117+
118+
if (values[0].length > 0 && validateNumeric(values[0])) {
119+
120+
if (values[1].length <= 0 || !validateNumeric(values[1])) {
121+
this.setState({ latitude: values[0] });
122+
this.longitudeRef.current.focus();
123+
this.longitudeRef.current.setSelectionRange(0, String(this.state.longitude).length);
124+
return;
125+
}
126+
127+
if (validateNumeric(values[1])) {
128+
this.setState({ latitude: values[0] });
129+
this.setState({ longitude: values[1] });
130+
this.longitudeRef.current.focus();
131+
return;
129132
}
130133
}
131134
}

0 commit comments

Comments
 (0)