Skip to content

Commit

Permalink
fix HTMLInputElement, add 28 tests, runs in FF
Browse files Browse the repository at this point in the history
  • Loading branch information
client9 committed Apr 23, 2010
1 parent a2e8203 commit 528d62d
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 10 deletions.
60 changes: 60 additions & 0 deletions specs/html/spec.js
Expand Up @@ -421,6 +421,66 @@ test('HTMLHtmlElement', function() {
equals(a.toString(), '[object HTMLHtmlElement]');
});

test('HTMLInputElement', function() {
var a = document.createElement('input');
ok(a, 'element created');
equals(a.toString(), '[object HTMLInputElement]');
equals(a.alt, '', 'empty alt is string');
a.alt = 'foo';
equals(a.alt, 'foo', 'set alt');

equals(a.src, '', 'empty src is string');

/**
* Checked is a virtual state, NOT an attribute
*
*/
equals(a.defaultChecked, false, 'defaultChecked value is false');
equals(a.checked, false, 'default checked value is false');
equals(a.getAttribute('checked'), null, 'getAttribte(checked) is null');
equals(a.hasAttribute('checked'), false, 'hasAttribute(checked) is false');

equals(typeof a.checked, 'boolean', 'default checked value is boolean');
a.checked = true;
equals(a.checked, true, 'set checked value is true');
equals(a.getAttribute('checked'), null, 'getAttribte(checked) is null');
equals(a.hasAttribute('checked'), false, 'hasAttribute(checked) is false');

a.checked = false;
equals(a.defaultChecked, false, 'defaultChecked value is still false');
a.defaultChecked = true;
equals(a.defaultChecked, true, 'set defaultChecked value is true');
equals(a.checked, false, 'set checked is still false');
equals(a.getAttribute('checked'), '', 'getAttribte(checked) is null');
equals(a.hasAttribute('checked'), true, 'hasAttribute(checked) is false');

equals(a.useMap, '', 'useMap is false');
equals(typeof a.useMap, 'string', 'default useMap value is boolean');

/**
* Numeric-like things
*/
equals(a.maxLength, -1, 'default maxLength');
equals(typeof a.maxLength, 'number', 'default maxLegth is number');

// FF says it's undefined!
//equals(typeof a.height, 'undefined', 'default height is undefined');
//equals(typeof a.width,'undefined', 'default width is undefined');

a.maxLength = '10';
equals(a.maxLength, 10, 'set maxLength');
equals(typeof a.maxLength, 'number', 'maxLength is number');

a.width = '10';
equals(a.width, 10, 'set width');
equals(typeof a.width, 'string', 'width is number');

a.height = '10';
equals(a.height, 10, 'set height');
equals(typeof a.height, 'string', 'height is number');

});

test('HTMLLabelElement', function() {
var element;

Expand Down
56 changes: 46 additions & 10 deletions src/html/input.js
@@ -1,52 +1,88 @@
/**
* HTMLInputElement - DOM Level 2
* HTMLInputElement
*
* HTML5: 4.10.5 The input element
* http://dev.w3.org/html5/spec/Overview.html#the-input-element
*/
HTMLInputElement = function(ownerDocument) {
HTMLInputAreaCommon.apply(this, arguments);
this._checked = null;
};
HTMLInputElement.prototype = new HTMLInputAreaCommon();
__extend__(HTMLInputElement.prototype, {
get alt(){
return this.getAttribute('alt');
return this.getAttribute('alt') || '';
},
set alt(value){
this.setAttribute('alt', value);
},

/**
* 'checked' returns state, NOT the value of the attribute
*/
get checked(){
return (this.getAttribute('checked') === 'checked');
if (this._checked === null) {
this._checked = this.defaultChecked;
}
return this._checked;
},
set checked(value){
this.setAttribute('checked', (value ? 'checked' :''));
// force to boolean value
this._checked = (value) ? true : false;
},

/**
* 'defaultChecked' actually reflects if the 'checked' attribute
* is present or not
*/
get defaultChecked(){
return this.getAttribute('defaultChecked');
return this.hasAttribute('checked');
},
set defaultChecked(val){
if (val) {
this.setAttribute('checked', '');
} else {
if (this.defaultChecked) {
this.removeAttribute('checked');
}
}
},

/**
* Height is a string
*/
get height(){
return this.getAttribute('height');
// spec says it is a string
return this.getAttribute('height') || '';
},
set height(value){
this.setAttribute('height',value);
},

/**
* MaxLength is a number
*/
get maxLength(){
return Number(this.getAttribute('maxlength')||'0');
return Number(this.getAttribute('maxlength')||'-1');
},
set maxLength(value){
this.setAttribute('maxlength', value);
},
get src(){
return this.getAttribute('src');
return this.getAttribute('src') || '';
},
set src(value){
this.setAttribute('src', value);
},
get useMap(){
return this.getAttribute('map');
return this.getAttribute('map') || '';
},

/**
* Width: spec says it is a string
*/
get width(){
return this.getAttribute('width');
return this.getAttribute('width') || '';
},
set width(value){
this.setAttribute('width',value);
Expand Down

0 comments on commit 528d62d

Please sign in to comment.