vitalets / x-editable

In-place editing with Twitter Bootstrap, jQuery UI or pure jQuery
http://vitalets.github.io/x-editable
MIT License
6.51k stars 1.72k forks source link

Bug when empty value in select where select elements are count from 0. #1049

Open kstalega opened 7 years ago

kstalega commented 7 years ago

Hi,

I think that I found bug in your code. To start with, I have select field with data-source set like this:

data-source="[{value: 0, text: 'Pan'}, {value: 1, text: 'Pani'}]"

and when this fields is empty it says that I've select option called 'Pan'. I tried to debug your code and I found that in http://cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.0/bootstrap3-editable/js/bootstrap-editable.js at line 790 there is comparision with double =. See: if(value == itemValue) { result.push(o); }

In this case value is "", and itemValue = 0, so "" == 0 => true. I think that there should be tripple ===, and it will return false as it should be.

What do you think? And besides, thank you very much for this very great pice of code!

kstalega commented 7 years ago

In my investigation I've changed:

if(value == itemValue) {
    result.push(o); 
}

to

if(String(value) === String(itemValue)) {
     result.push(o); 
}

And in my case it works as expect, but I need make more tests. What do you think about that?