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

Changeset 6530

Show
Ignore:
Timestamp:
04/16/07 11:27:47 (1 year ago)
Author:
mislav
Message:

changed $F getter/setter to always return the value for consistency

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinoffs/prototype/branches/form/src/form.js

    r6529 r6530  
    187187var Field = Form.Element; 
    188188var $F = function(element, value) { 
    189   return Form.Element[value === undefined ? 'getValue' : 'setValue'](element, value);  
     189  return value === undefined ? Form.Element.getValue(element) : 
     190    (Form.Element.setValue(element, value), value); 
    190191} 
    191192 
  • spinoffs/prototype/branches/form/test/unit/form.html

    r6529 r6530  
    391391      var input = $('input_enabled'); 
    392392      input.setValue('foo'); 
    393       assertEqual('foo', input.getValue()); 
    394       input.setValue(input.getAttribute('value')); 
     393      assertEqual('foo', input.getValue(), 'value improperly set'); 
     394 
     395      // shortcut method always returns value 
     396      assertEqual('bar', $F('input_enabled', 'bar'), 
     397        '$F should return value even if setter'); 
     398      assertEqual('bar', $F('input_enabled'), 'value improperly set by $F'); 
     399      // ... but setValue allows for chaining 
     400      assertEqual(input, input.setValue(input.getAttribute('value')), 
     401        'setValue chaining is broken'); 
     402 
    395403      // checkbox 
    396404      input = $('checkbox_hack'); 
    397405      input.setValue(false); 
    398       assertEqual(null, input.getValue()); 
     406      assertEqual(null, input.getValue(), 'checkbox should be unchecked'); 
    399407      input.setValue(true); 
    400       assertEqual("1", input.getValue()); 
     408      assertEqual("1", input.getValue(), 'checkbox should be checked'); 
    401409      // selectbox 
    402410      input = $('form_selects')['vu']; 
    403411      input.setValue('3'); 
    404       assertEqual('3', input.getValue()); 
     412      assertEqual('3', input.getValue(), 'single select option improperly set'); 
    405413      input.setValue('1'); 
    406414      assertEqual('1', input.getValue()); 
     
    408416      input = $('form_selects')['vm[]']; 
    409417      input.setValue(['2', '3']); 
    410       assertEnumEqual(['2', '3'], input.getValue()); 
     418      assertEnumEqual(['2', '3'], input.getValue(), 
     419        'multiple select options improperly set'); 
    411420      // should this work? 
    412421      // input.setValue('1');