Kolyunya / yii2-map-input-widget

A Yii2 input widget which provides a user-friendly interface for selecting geographical coordinates via Google maps. Allows users to select geographical coordinates by clicking on an interative Google map embedded into your web-page. Also allows users to type in a place name to search for it via Google Places API.
http://kolyunya.github.io/yii2-map-input-widget/
GNU General Public License v3.0
28 stars 24 forks source link

Need to fix the negative number intake #7

Closed sinaru closed 9 years ago

sinaru commented 9 years ago

Your code is ignoring the negative positions. So I have modifiedl the JavaScript file current regular expression to match negative numbers. Just enocuntered this issue when I was refferring locations in negative longitudes (such as in USA). Hope my regular expression fix is correct, it worked for me. : )

Kolyunya commented 9 years ago

@sinaru thank you very much for your contribution. I've fixed the error and made my own commit with a little bit corrected regular expression.

Kolyunya commented 9 years ago

@sinaru the fix is available in the patch 1.0.2.

sinaru commented 9 years ago

@Kolyunya So you end up using my change ^^. Just wondered what you changed since you said that you have corrected the regular expression a little.

Kolyunya commented 9 years ago

@sinaru in fact I did not end up using you change. Note that in your patch the -? token is in square braces and [-?\d.]+ matches any string consisting from any number of -, ?, . symbols or any digit. That means that this pattern will match even ?-0-1-2.?-3-4? string. This does not make much sense, does it? But in my patch the -? is located outside the square braces and means a single and optional instance of the -. Please correct me if I'm mistaking somehow.

sinaru commented 9 years ago

Hi my bad. I didnt see where you have put the ? I was just trying to find a fix and found ? is used to indicate optional value. Still learning regular expressions. :jack_o_lantern:

It was working ok since the string provided would contain proper decimal numbers, but you are right it will also match if it contains ?. Then again current regular expression would also match "-45.6.9". Maybe should put the (.) dot outside the square brackets? ex: /-?[\d]+.[\d]+/g

https://jsfiddle.net/qr400dqt/

Kolyunya commented 9 years ago

@sinaru your regular expression is not gonna work as you expect for integer values e. g. 42. The dot and the fractional part should be optional.

Also the . is not the dot: it's a special character meaning any character. The dot is represented by the \. token in regular expressions.

The final expression should be something like -?\d+(\.\d+)?. I'm gonna make a patch soon.

Kolyunya commented 9 years ago

@sinaru done in patch 1.0.3.