Skip to content
Browse files

Merge pull request #2188 from arian/fix-2178-set-input-type

Fixes #2178 - A input field should keep its value even when the type property is changed (in IE)
  • Loading branch information...
2 parents bf1d54c + 4f6981e commit 0664977ca763c7af1b3cfececeb7b5cff32ca2ac @ibolmotest ibolmotest committed Jan 30, 2012
Showing with 28 additions and 0 deletions.
  1. +1 −0 Docs/Element/Element.md
  2. +12 −0 Source/Element/Element.js
  3. +15 −0 Specs/1.4client/Element/Element.js
View
1 Docs/Element/Element.md
@@ -319,6 +319,7 @@ This is a "dynamic arguments" method. Properties passed in can be any of the 'se
- use 'class', not 'className'
- use 'frameborder', not 'frameBorder'
- etc.
+- In IE8 or lower, it is not possible to set `type` multiple times. It will throw an error.
### See Also:
View
12 Source/Element/Element.js
@@ -589,6 +589,18 @@ if (el.type != 'button') propertySetters.type = function(node, value){
el = null;
/* </webkit> */
+/*<IE>*/
+var input = document.createElement('input');
+input.value = 't';
+input.type = 'submit';
+if (input.value != 't') propertySetters.type = function(node, type){
+ var value = node.value;
+ node.type = type;
+ node.value = value;
+};
+input = null;
+/*</IE>*/
+
/* getProperty, setProperty */
/* <ltIE9> */
View
15 Specs/1.4client/Element/Element.js
@@ -81,6 +81,21 @@ describe('Element', function(){
});
+ describe("Element.setProperty('type')", function(){
+
+ it('should keep the input value after setting a input field to another type (submit button)', function(){
+ var input = new Element('input', {value: 'myValue', type: 'text'});
+ input.setProperty('type', 'submit');
+ expect(input.getProperty('value')).toEqual('myValue');
+ });
+
+ it('should set the right type and value of input fields when a input field is created with CSS selectors', function(){
+ var input = new Element('input[type="submit"]', {value: 'myValue'});
+ expect(input.getProperty('value')).toEqual('myValue');
+ });
+
+ });
+
describe('Element.get', function(){
describe('value', function(){

0 comments on commit 0664977

Please sign in to comment.
Something went wrong with that request. Please try again.