From 1f90bcb8b5d0929fd91f5a5268e4b4cae04d4b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Fri, 2 Sep 2011 10:41:19 +0200 Subject: [PATCH] val(value) now accepts a function argument --- src/zepto.js | 4 ++-- test/zepto.html | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/zepto.js b/src/zepto.js index f1d218f1d..a330bab59 100644 --- a/src/zepto.js +++ b/src/zepto.js @@ -314,8 +314,8 @@ var Zepto = (function() { val: function(value){ return (value === undefined) ? (this.length > 0 ? this[0].value : null) : - this.each(function(){ - this.value = value; + this.each(function(idx){ + this.value = funcArg(this, value, idx, this.value); }); }, offset: function(){ diff --git a/test/zepto.html b/test/zepto.html index 9b8c895b1..6be75253b 100644 --- a/test/zepto.html +++ b/test/zepto.html @@ -1352,6 +1352,9 @@

Zepto DOM unit tests

input.get(0).value = 'Hello again'; t.assertEqual('Hello again', input.val()); + + input.val(function(i, val){ return val.replace('Hello', 'Bye') }); + t.assertEqual('Bye again', input.val()); }, testChaining: function(t){