开发者

Symfony sfWidgetFormChoice default disabled value

The widget looks like this:

$this->widgetSchema['tara'] = new sfWidg开发者_开发技巧etFormChoice(array(
    'choices'  => Doctrine_Core::getTable('Users')->getCountry(),
    'expanded' => false,
    'multiple' => false,
));

And the getCountry function:

static public $country = array(
    '1' => 'România',
    '2' => 'United States',
    '3' => 'France',
);

public function getCountry()
{
    return self::$country;
}

Now the widget renders like this:

  • România
  • United States
  • France

But I want it to look like this:

  • Choose a country - The default and disabled option, which shouldn't be validated by the form
  • România
  • United Stated
  • France

How can I do this?


You can either add an 'empty' option to your array:

static public $country = array(
    '' => 'Choose a country',
    '1' => 'România',
    '2' => 'United States',
    '3' => 'France',
);

and validate accordingly.

Or you could implement your own sfWidgetFormChoice-based class, which could add a add_empty option (much like the sfWidgetFormDoctrineChoice).


static public $country = array(
    '' => 'Choose a country',
    '1' => 'România',
    '2' => 'United States',
    '3' => 'France',
);

Then use this to disable:

$this->widgetSchema ['tara']->setAttribute('disabled','disable');

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜