How to disable form element in symfony?

I am using a Select element in the form

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

I want this city element to be disabled for the first time the page loads. and when you select a country, the city element will be turned on (it will be loaded via an AJAX call)

+4
source share
4 answers

You can disable this feature.

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

+10
source

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

+6
source

If you have already loaded the second list data via AJAX, why don't you disable and enable the second list through Javascript?

Disabling can be done either hard-coded in a template (with simple HTML) or using Javascript (after loading the document).

To enable, use the callback method to call AJAX (if successful).

One might know how you actually make an AJAX call (jquery?).

0
source

Well, the cleanest way is to learn “how to write your own widget” and actually write. You can take a look at sfWidgetFormDate as an example.

0
source

All Articles