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: Pasting location coordinates into field of type GeoPoint does not work in data browser #2464

Merged
merged 7 commits into from
Jun 20, 2023
Merged
43 changes: 23 additions & 20 deletions src/components/GeoPointEditor/GeoPointEditor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /[[("' ]?(?<x>[0-9.]+)["' ]?,["' ]?(?<y>[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;
}
}
}
Expand Down