tuupola / jquery_chained

Chained Selects for jQuery and Zepto
https://appelsiini.net/projects/chained/
589 stars 283 forks source link

Plugin doesn't work if data-chained values are numerics only. #60

Closed Maniac206 closed 7 years ago

Maniac206 commented 7 years ago

The plugin fails to init if the data-chained property only contains one numeric (ex: an ID).

HTML :

 <select id="mark" name="mark">
    <option value="">--</option>
    <option value="1">BMW</option>
    <option value="2">Audi</option>
</select>
<select id="series" name="series">
    <option value="">--</option>
    <option value="series-3" data-chained="1">3 series</option>
    <option value="series-5" data-chained="1">5 series</option>
    <option value="series-6" data-chained="1">6 series</option>
    <option value="a3" data-chained="2">A3</option>
    <option value="a4" data-chained="2">A4</option>
    <option value="a5" data-chained="2">A5</option>
</select>

Line 79 in jquery.chained.js :

if (data) {
    matches = data.split(" ");
}

This case will throw the following error : "Uncaught TypeError: data.split is not a function". Right now, doing a toString() before the split solves the problem for me.

Line 79 in jquery.chained.js :

if (data) {
    matches = data.toString().split(" ");
}
Maniac206 commented 7 years ago

Sorry, duplicate of https://github.com/tuupola/jquery_chained/issues/58