Skip to content

Commit e1a1aef

Browse files
committed
jQuery #12600: attrHooks.value
1 parent 4c5bf7a commit e1a1aef

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/attributes.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,22 @@ jQuery.attr = function( elem, name, value, pass ) {
1919
}
2020
return attr.call( jQuery, elem, name, value );
2121
};
22+
23+
// attrHooks: value
24+
compatWarnProp( jQuery.attrHooks, "value", {
25+
get: function( elem, name ) {
26+
if ( jQuery.nodeName( elem, "button" ) ) {
27+
return attr.call( jQuery, elem, name );
28+
}
29+
return name in elem ?
30+
elem.value :
31+
null;
32+
},
33+
set: function( elem, value, name ) {
34+
if ( jQuery.nodeName( elem, "button" ) ) {
35+
return attr.call( jQuery, elem, value, name );
36+
}
37+
// Does not return so that setAttribute is also used
38+
elem.value = value;
39+
}
40+
}, "jQuery.attrHooks[\"value\"] is deprecated" );

test/attributes.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,21 @@ test( "attr(jquery_method)", function() {
6767

6868
equal( jQuery.compatWarnings.length, warnLength + 1, ".attr(props, true) warned" );
6969
});
70+
71+
test( "attrHooks[\"value\"]", function() {
72+
expect( 6 );
73+
var warnLength = jQuery.compatWarnings.length;
74+
75+
equal( jQuery("<input/>").attr("value"), "", "input.attr('value') returns value property." );
76+
equal( jQuery("#area1").attr("value"), "foobar", "textarea.attr('value') returns value property." );
77+
78+
equal( jQuery.compatWarnings.length, warnLength + 1, ".attr('value') warned" );
79+
80+
jQuery.compatReset();
81+
82+
jQuery("#text1").attr( "value", "foo" );
83+
equal( jQuery("#text1")[0].getAttributeNode("value").value, "foo", ".attr( 'value', val ) sets value attribute." );
84+
equal( jQuery("#text1")[0].value, "foo", ".attr( 'value', val ) sets value property." );
85+
86+
equal( jQuery.compatWarnings.length, 1, ".attr( 'value', val ) warned" );
87+
});

0 commit comments

Comments
 (0)