Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6660

Show
Ignore:
Timestamp:
05/05/07 09:39:19 (1 year ago)
Author:
tobie
Message:

Make Element#update work for SELECT tags in IE and Opera.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinoffs/prototype/branches/dom/CHANGELOG

    r6658 r6660  
    11*SVN* 
     2 
     3* Make Element#update work for SELECT tags in IE and Opera. [Tobie Langel] 
    24 
    35* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel] 
  • spinoffs/prototype/branches/dom/src/dom.js

    r6659 r6660  
    662662          element.appendChild(node) 
    663663      }); 
     664    } else if(tagName == 'SELECT') { 
     665      while (element.length > 0) element.remove(element.length - 1); 
     666      Element._getContentFromAnonymousSelect(html.stripScripts()) 
     667        .each(function(option) { element.add(option) }); 
    664668    } else element.innerHTML = html.stripScripts(); 
    665  
    666669    html.evalScripts.bind(html).defer(); 
    667670    return element; 
    668671  }; 
    669672} 
     673 
     674Element._getContentFromAnonymousSelect = function(html) { 
     675  var div = document.createElement('div'); 
     676  div.innerHTML = '<select>' + html + '</select>'; 
     677  return $A(div.firstChild.childNodes).map(function(o) { 
     678    return new Option(o.text, o.value === undefined ? o.value : o.text, o.selected, o.selected); 
     679  }); 
     680}; 
    670681 
    671682Element._getContentFromAnonymousTable = function(html, tagName) { 
  • spinoffs/prototype/branches/dom/test/unit/dom.html

    r6658 r6660  
    295295<table id="table_for_insertions"></table> 
    296296<table id="table_for_row_insertions"><tr id="row_1"></tr></table> 
     297<form method="post" action="blah"> 
     298  <select id="select_for_update" name="select_for_update"> 
     299    <option>option 1</option> 
     300    <option>option 2</option> 
     301  </select> 
     302</form> 
    297303<div id="wrap-container"><p id="wrap"></p></div> 
    298304<!-- Tests follow --> 
     
    522528    }}, 
    523529     
     530    testElementUpdateInSelect: function() {with(this) { 
     531      var select = $('select_for_update'); 
     532      select.update('<option value="3">option 3</option><option selected="selected">option 4</option>'); 
     533      assertEqual('option 4', select.getValue()); 
     534    }}, 
     535     
    524536    testElementReplace: function() {with(this) { 
    525537      $('testdiv-replace-1').replace('hello from div!');