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
46 changes: 26 additions & 20 deletions src/components/GeoPointEditor/GeoPointEditor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,32 @@ 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;
}
// This regex will match this form of input: (x, y) or (x,y) or x, y or x,y
const regex = /\((-?\d+\.?\d*),\s*(-?\d+\.?\d*)\)|(-?\d+\.?\d*),\s*(-?\d+\.?\d*)/;
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
const match = value.match(regex);

if (!match) {
return null;
}

let values = match[0].replace(/[()]/g, '').split(',');

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;
}
}
}
Expand Down