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

Ticket #9609: serialize_elements_patch_test.diff

File serialize_elements_patch_test.diff, 1.7 kB (added by kangax, 1 year ago)

unified patch/test

  • test/unit/form.html

    old new  
    124124      <input type="checkbox" id="ffe_ti2_checkbox" tabindex="0" /> 
    125125      <input type="submit" id="ffe_ti2_submit" tabindex="1" /> 
    126126    </form> 
     127     
     128    <form id="trouble_form"> 
     129        <input type="text" name="length" value="foo" /> 
     130        <input type="text" name="toString" value="55" /> 
     131        <input type="text" name="valueOf" value="bar" /> 
     132    </form> 
    127133  </div> 
    128134 
    129135  <!-- Tests follow --> 
     
    400406                      $('form').serialize({ submit: false })); 
    401407      assertHashEqual({ val1:4, action:'blah' }, 
    402408                      $('form').serialize({ submit: 'inexistent' })); 
     409     
     410      // try to serialize form containing toString, valueOf and length -named elements 
     411      assertHashEqual({ length: 'foo', toString: 55, valueOf: 'bar' }, 
     412                      $('trouble_form').serialize(true)); 
    403413    }}, 
    404414     
    405415    testFormMethodsOnExtendedElements: function() {with(this) { 
  • src/form.js

    old new  
    1414        key = element.name; value = $(element).getValue(); 
    1515        if (value != null && (element.type != 'submit' || (!submitted && 
    1616            submit !== false && (!submit || key == submit) && (submitted = true)))) {  
    17           if (key in result) { 
     17          if (key in result && !Object.isFunction(result[key])) { 
    1818            // a key is already present; construct an array of values 
    1919            if (!Object.isArray(result[key])) result[key] = [result[key]]; 
    2020            result[key].push(value);