Development

Changeset 8978

You must first sign up to be able to contribute.

Changeset 8978

Show
Ignore:
Timestamp:
05/15/08 12:10:09 (2 months ago)
Author:
fabien
Message:

fixed sfWidgetFormSelect behavior for the value attribute which is now always present, even if the value is empty

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/widget/sfWidgetFormSelect.class.php

    r8906 r8978  
    9595    return $options; 
    9696  } 
     97 
     98  /** 
     99   * @see sfWidget 
     100   * 
     101   * We always generate an attribute for the value. 
     102   */ 
     103  protected function attributesToHtmlCallback($k, $v) 
     104  { 
     105    return is_null($v) || ('' === $v && 'value' != $k) ? '' : sprintf(' %s="%s"', $k, $this->escapeOnce($v)); 
     106  } 
    97107} 
  • branches/1.1/test/unit/widget/sfWidgetFormSelectTest.php

    r8906 r8978  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(14, new lime_output_color()); 
     13$t = new lime_test(16, new lime_output_color()); 
    1414 
    1515$dom = new DomDocument('1.0', 'utf-8'); 
     
    2424$t->is($css->matchSingle('#foo option[value="foobar"][selected="selected"]')->getValue(), 'foo', '->render() renders a select tag with the value selected'); 
    2525$t->is(count($css->matchAll('#foo option')->getNodes()), 2, '->render() renders all choices as option tags'); 
     26 
     27// value attribute is always mandatory 
     28$w = new sfWidgetFormSelect(array('choices' => array('' => 'bar'))); 
     29$t->like($w->render('foo', 'foobar'), '/<option value="">/', '->render() always generate a value attribute, even for empty keys'); 
     30 
     31// other attributes are removed is empty 
     32$w = new sfWidgetFormSelect(array('choices' => array('' => 'bar'))); 
     33$t->like($w->render('foo', 'foobar', array('class' => '', 'style' => null)), '/<option value="">/', '->render() always generate a value attribute, even for empty keys'); 
    2634 
    2735// multiple select