Skip to content

jQuery #12600: attrHooks.value #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,22 @@ jQuery.attr = function( elem, name, value, pass ) {
}
return attr.call( jQuery, elem, name, value );
};

// attrHooks: value
compatWarnProp( jQuery.attrHooks, "value", {
get: function( elem, name ) {
if ( jQuery.nodeName( elem, "button" ) ) {
return attr.call( jQuery, elem, name );
}
return name in elem ?
elem.value :
null;
},
set: function( elem, value, name ) {
if ( jQuery.nodeName( elem, "button" ) ) {
return attr.call( jQuery, elem, value, name );
}
// Does not return so that setAttribute is also used
elem.value = value;
}
}, "jQuery.attrHooks[\"value\"] is deprecated" );
18 changes: 18 additions & 0 deletions test/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,21 @@ test( "attr(jquery_method)", function() {

equal( jQuery.compatWarnings.length, warnLength + 1, ".attr(props, true) warned" );
});

test( "attrHooks[\"value\"]", function() {
expect( 6 );
var warnLength = jQuery.compatWarnings.length;

equal( jQuery("<input/>").attr("value"), "", "input.attr('value') returns value property." );
equal( jQuery("#area1").attr("value"), "foobar", "textarea.attr('value') returns value property." );

equal( jQuery.compatWarnings.length, warnLength + 1, ".attr('value') warned" );

jQuery.compatReset();

jQuery("#text1").attr( "value", "foo" );
equal( jQuery("#text1")[0].getAttributeNode("value").value, "foo", ".attr( 'value', val ) sets value attribute." );
equal( jQuery("#text1")[0].value, "foo", ".attr( 'value', val ) sets value property." );

equal( jQuery.compatWarnings.length, 1, ".attr( 'value', val ) warned" );
});