开发者

How to disable a form element in symfony?

I am using a Select element, in form

'country' =>new sfWidgetFormChoice(array('choices' => CountryPeer::getAllCountry())),

'city' =>new sfWidgetFormChoice(array('choices' => CityPeer::g开发者_运维百科etAllCity())),

i want that city element to be disabled, at the first time when the page loads. and on selection of country the city element will be enabled.(it will be loaded through AJAX call)


You can disable like this

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


$this->widgetSchema['field']->setAttribute('readonly', 'readonly');


If you already load the data of the second list via AJAX, why don't you disable and enable the second list via Javascript?

The disabling could be done either hardcoded in the template (with plain HTML) or done by Javascript (after document load).

For the enabling, use a callback method for the AJAX call (on the success event).

It would be could to know, how you actually do the AJAX call (jquery?).


Well, most clean way is to learn "how to write your own widget" and actually write it. You can take a look at sfWidgetFormDate as a rough example.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜