Skip to content

Commit

Permalink
Refactor fn.val() implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Jul 12, 2016
1 parent aba24c7 commit f5500eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/zepto.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,15 +655,16 @@ var Zepto = (function() {
return data !== null ? deserializeValue(data) : undefined
},
val: function(value){
if (value == null) value = ""
return 0 in arguments ?
this.each(function(idx){
if (0 in arguments) {
if (value == null) value = ""
return this.each(function(idx){
this.value = funcArg(this, value, idx, this.value)
}) :
(this[0] && (this[0].multiple ?
})
} else {
return this[0] && (this[0].multiple ?
$(this[0]).find('option').filter(function(){ return this.selected }).pluck('value') :
this[0].value)
)
}
},
offset: function(coordinates){
if (coordinates) return this.each(function(index){
Expand Down
5 changes: 4 additions & 1 deletion test/zepto.html
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,10 @@ <h1>Zepto Core unit tests</h1>

t.assertEqual('Hello World', input.val())

input.val(undefined);
input.val(undefined)
t.assertEqual('', input.val())

input.val(null)
t.assertEqual('', input.val())

input.val('')
Expand Down

0 comments on commit f5500eb

Please sign in to comment.