Skip to content

Commit 1d00356

Browse files
author
Peter
committed
instead of string check use isResolved;keypress -> keyup
1 parent b5e771d commit 1d00356

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

web/src/main/webapp/js/ghrequest.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ GHInput = function(str) {
103103
}
104104
};
105105

106+
GHInput.prototype.isResolved = function() {
107+
return this.lat && this.lng;
108+
}
109+
106110
GHInput.prototype.setCoord = function(lat, lng) {
107111
this.resolvedText = "";
108112
this.lat = round(lat);

web/src/main/webapp/js/main.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ $(document).ready(function(e) {
100100

101101
function resolveCoords(fromStr, toStr) {
102102
routingLayer.clearLayers();
103-
if(fromStr != ghRequest.from.input)
103+
if(fromStr !== ghRequest.from.input || !ghRequest.from.isResolved())
104104
ghRequest.from = new GHInput(fromStr);
105105

106-
if(toStr != ghRequest.to.input)
106+
if(toStr !== ghRequest.to.input || !ghRequest.to.isResolved())
107107
ghRequest.to = new GHInput(toStr);
108108

109109
if(ghRequest.from.lat && ghRequest.to.lat) {
@@ -260,7 +260,7 @@ function resolve(fromOrTo, point) {
260260
return getInfoFromLocation(point).done(function() {
261261
$("#" + fromOrTo + "Input").val(point.input);
262262
if(point.resolvedText)
263-
$("#" + fromOrTo + "Found").html(point.resolvedText);
263+
$("#" + fromOrTo + "Found").html(point.resolvedText);
264264

265265
$("#" + fromOrTo + "Flag").show();
266266
$("#" + fromOrTo + "Indicator").hide();
@@ -566,25 +566,25 @@ function initForm() {
566566
e.preventDefault();
567567
});
568568

569+
// use keyup instead keypress otherwise the val() calls could contain partial values
569570
// if FROM will be submitted
570-
$('#fromInput').keypress(function(e) {
571+
$('#fromInput').keyup(function(e) {
571572
if(e.which == 13) {
572573
var from = $("#fromInput").val()
573574
var to = $("#toInput").val();
574575
// do not resolve 'to'
575-
if(to == "To") {
576-
if(from != ghRequest.from.input)
577-
ghRequest.from = new GHInput(from);
576+
if(to == "To") {
577+
ghRequest.from = new GHInput(from);
578578
$.when(resolveFrom()).done(function() {
579579
focus(ghRequest.from);
580-
});
580+
});
581581
} else
582582
resolveCoords(from, to);
583583
}
584584
});
585585

586586
// if TO will be submitted
587-
$('#toInput').keypress(function(e) {
587+
$('#toInput').keyup(function(e) {
588588
if(e.which == 13) {
589589
var from = $("#fromInput").val();
590590
if(from == "From") {

0 commit comments

Comments
 (0)