diff --git a/Source/Element/Element.js b/Source/Element/Element.js index f79683345..49517fa3a 100644 --- a/Source/Element/Element.js +++ b/Source/Element/Element.js @@ -217,17 +217,20 @@ var escapeQuotes = function(html){ Document.implement({ newElement: function(tag, props){ - if (props && props.checked != null) props.defaultChecked = props.checked; - /**/// Fix for readonly name and type properties in IE < 8 - if (createElementAcceptsHTML && props){ - tag = '<' + tag; - if (props.name) tag += ' name="' + escapeQuotes(props.name) + '"'; - if (props.type) tag += ' type="' + escapeQuotes(props.type) + '"'; - tag += '>'; - delete props.name; - delete props.type; + if (props){ + if (props.checked != null) props.defaultChecked = props.checked; + if ((props.type == 'checkbox' || props.type == 'radio') && props.value == null) props.value = 'on'; + /**/// Fix for readonly name and type properties in IE < 8 + if (createElementAcceptsHTML){ + tag = '<' + tag; + if (props.name) tag += ' name="' + escapeQuotes(props.name) + '"'; + if (props.type) tag += ' type="' + escapeQuotes(props.type) + '"'; + tag += '>'; + delete props.name; + delete props.type; + } + /**/ } - /**/ return this.id(this.createElement(tag)).set(props); } diff --git a/Specs/Element/Element.js b/Specs/Element/Element.js index 8661bccc2..320195b96 100644 --- a/Specs/Element/Element.js +++ b/Specs/Element/Element.js @@ -2586,3 +2586,36 @@ describe('Element', function(){ }); }); +describe('normalize value for new Element type == checkbox || radio', function(){ + + it('value of new created checkbox should be "on" if none specified', function() { + var input = new Element('input', { + type: 'checkbox' + }); + input.set('checked', true); + expect(input.get('value')).toEqual('on'); + }); + it('value of new created checkbox should be the specified in constructor', function() { + var input = new Element('input', { + type: 'checkbox', + value: 'someValue' + }); + input.set('checked', true); + expect(input.get('value')).toEqual('someValue'); + }); + it('value of new created radio button should be "on" if none specified', function() { + var input = new Element('input', { + type: 'radio' + }); + input.set('checked', true); + expect(input.get('value')).toEqual('on'); + }); + it('value of new created radio should be the specified in constructor', function() { + var input = new Element('input', { + type: 'radio', + value: 'someValue' + }); + input.set('checked', true); + expect(input.get('value')).toEqual('someValue'); + }); +});