Skip to content

Commit 8e52d3b

Browse files
Sam Schoolerdrew-gross
authored andcommitted
Add point spliting and auto focusing to the GeoPointEditor (#373)
1 parent 03d05e9 commit 8e52d3b

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/components/GeoPointEditor/GeoPointEditor.react.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default class GeoPointEditor extends React.Component {
4646
}
4747

4848
handleKeyLatitude(e) {
49-
if (e.keyCode === 13) {
49+
if (e.keyCode === 13 || e.keyCode === 44) {
5050
this.refs.longitude.focus();
5151
this.refs.longitude.setSelectionRange(0, String(this.state.longitude).length);
5252
}
@@ -83,6 +83,34 @@ export default class GeoPointEditor extends React.Component {
8383
render() {
8484
let onChange = (target, e) => {
8585
let value = e.target.value;
86+
87+
if (!validateNumeric(value)) {
88+
var values = value.split(",");
89+
90+
if (values.length == 2) {
91+
values = values.map(function(val) {
92+
return val.trim();
93+
});
94+
95+
if(values[0].length > 0 && validateNumeric(values[0])) {
96+
97+
if(values[1].length <= 0 || !validateNumeric(values[1])) {
98+
this.setState({ ["latitude"]: values[0] });
99+
this.refs.longitude.focus();
100+
this.refs.longitude.setSelectionRange(0, String(this.state.longitude).length);
101+
return;
102+
}
103+
104+
if (validateNumeric(values[1])) {
105+
this.setState({ ["latitude"]: values[0] });
106+
this.setState({ ["longitude"]: values[1] });
107+
this.refs.longitude.focus();
108+
return;
109+
}
110+
}
111+
}
112+
}
113+
86114
this.setState({ [target]: validateNumeric(value) ? value : this.state[target] });
87115
};
88116
return (

0 commit comments

Comments
 (0)