Skip to content

Commit

Permalink
fix val() for select multiple; fixes madrobby#501
Browse files Browse the repository at this point in the history
  • Loading branch information
madrobby committed May 2, 2012
1 parent 7cf9c7a commit 9d6515c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/zepto.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,9 @@ var Zepto = (function() {
},
val: function(value){
return (value === undefined) ?
(this.length > 0 ? (this[0].multiple ? $(this[0]).find('option[selected]').pluck('value') : this[0].value) : undefined) :
(this.length > 0 ?
(this[0].multiple ? $(this[0]).find('option').not(function(o){ return !this.selected }).pluck('value') : this[0].value) :
undefined) :
this.each(function(idx){
this.value = funcArg(this, value, idx, this.value)
})
Expand Down
4 changes: 3 additions & 1 deletion test/zepto.html
Original file line number Diff line number Diff line change
Expand Up @@ -1337,8 +1337,10 @@ <h1>Zepto DOM unit tests</h1>

var multiple =
$('<select multiple><option selected>1</option><option value=2 selected="selected">a</option><option>3</option></select>')
t.assertEqualCollection(['1','2'], multiple.val())

t.assertEqualCollection([1,2], multiple.val())
multiple.find('option')[0].selected = false
t.assertEqualCollection(['2'], multiple.val())
},

testChaining: function(t){
Expand Down

0 comments on commit 9d6515c

Please sign in to comment.