Skip to content

Commit

Permalink
fix: Pasting location coordinates into field of type GeoPoint does …
Browse files Browse the repository at this point in the history
…not work in data browser (parse-community#2464)
  • Loading branch information
patelmilanun authored Jun 20, 2023
1 parent 5293640 commit a8ce343
Showing 1 changed file with 23 additions and 20 deletions.
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

0 comments on commit a8ce343

Please sign in to comment.