Harish Kurup
Harish Kurup

Reputation: 7505

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::getAllCity())),

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)

Upvotes: 4

Views: 11543

Answers (4)

tirenweb
tirenweb

Reputation: 31709

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

Upvotes: 6

metoikos
metoikos

Reputation: 1364

You can disable like this

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

Upvotes: 9

Andrei Dziahel
Andrei Dziahel

Reputation: 969

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.

Upvotes: 0

Felix Kling
Felix Kling

Reputation: 816364

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?).

Upvotes: 0

Related Questions