Skip to content
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

[dom] Normalize setting a node value to null #1611

Merged
merged 1 commit into from
Feb 12, 2014
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
2 changes: 2 additions & 0 deletions src/dom/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ DOM Change History
@VERSION@
------

* [#1603][]: Set a node value to an empty string setting to null. [Ryuichi Okumura]
* [#1469][]: Fix a bug with setStyle() cannot set an opacity to 1. [Ryuichi Okumura]

[#1603]: https://github.com/yui/yui3/issues/1603
[#1469]: https://github.com/yui/yui3/issues/1469

3.14.1
Expand Down
2 changes: 1 addition & 1 deletion src/dom/js/dom-attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Y.mix(Y_DOM, {

if (node && node[TAG_NAME]) {
setter = Y_DOM.VALUE_SETTERS[node[TAG_NAME].toLowerCase()];

val = (val === null) ? '' : val;
if (setter) {
setter(node, val);
} else {
Expand Down
39 changes: 39 additions & 0 deletions src/dom/tests/unit/assets/dom-core-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,16 @@ YUI.add('dom-core-test', function(Y) {
node.removeAttribute('value')
},

'value updated from null should be empty string': function() {
var node = document.getElementById('test-text-no-value'),
val = null;

Y.DOM.setValue(node, val);
Assert.areEqual('', Y.DOM.getValue(node));
Y.DOM.setValue(node, '');
node.removeAttribute('value');
},

'textarea from html value should match new value': function() {
var node = document.getElementById('test-textarea-text-value'),
val = 'new textarea test';
Expand All @@ -1436,6 +1446,15 @@ YUI.add('dom-core-test', function(Y) {
Y.DOM.setValue('');
},

'textarea from null should be empty string': function() {
var node = document.getElementById('test-textarea-no-value'),
val = null;

Y.DOM.setValue(node, val);
Assert.areEqual('', Y.DOM.getValue(node));
Y.DOM.setValue('');
},

'button value should match updated value': function() {
var node = document.getElementById('test-button-value'),
val = 'new value';
Expand Down Expand Up @@ -1464,6 +1483,16 @@ YUI.add('dom-core-test', function(Y) {
node.removeAttribute('value')
},

'button value updated from null should be empty string': function() {
var node = document.getElementById('test-button-no-value'),
val = null;

Y.DOM.setValue(node, val);
Assert.areEqual('', Y.DOM.getValue(node));
Y.DOM.setValue(node, '');
node.removeAttribute('value');
},

'option value should match updated value': function() {
var node = document.getElementById('test-option-value'),
val = 'new value';
Expand Down Expand Up @@ -1499,6 +1528,16 @@ YUI.add('dom-core-test', function(Y) {
Assert.areEqual(val, Y.DOM.getValue(node));
Y.DOM.setValue(node, '');
node.removeAttribute('value')
},

'option value updated from null should be null': function() {
var node = document.getElementById('test-option-no-value'),
val = null;

Y.DOM.setValue(node, val);
Assert.areEqual('', Y.DOM.getValue(node));
Y.DOM.setValue(node, '');
node.removeAttribute('value');
}
}));

Expand Down