Me estoy volviendo loco con los selects anidados, tengo 3 DB countries, provinces, cities, todas con los campos id y nombre y el siguiente código
// app/views/cities/add.ctp <div class="cities form"> <?php $this->Html->script('views/countries/list_provinces.js', array('inline' => FALSE)); ?> <?php echo $this->Form->create('City'); ?> <fieldset> <legend><?php __('Add City'); ?></legend> <?php //echo $this->element('form_city'); ?> <?php echo $this->Form->input('nombre'); ?> <?php echo $this->Form->input('country_id', array('empty' => 'Seleccione Pais', 'id' => 'country')); ?> <div id="provinces" style="display: none;"> <?php echo $this->Form->input('province_id', array('type' => 'select', 'id' => 'province')); ?> </div> </fieldset> <?php echo $this->Form->end(__('Submit', true)); ?> // app/views/countries/list_provinces.js $(document).ready(function(){ $('#country').live('change', function() { if($(this).val().length != 0) { $.getJSON('/countries/get_provinces_ajax', {countryId: $(this).val()}, function(provinces) { if(provinces !== null) { populateprovincesList(provinces); } }); } }); }); function populateProvinceList(Provinces) { var options = ''; $.each(Provinces, function(index, province) { options += '<option value="' + index + '">' + province + '</ option>'; }); $('#province').html(options); $('#provinces').show(); } // app/controlles/countris_controller.php <?php class CountriesController extends AppController { var $name = 'Countries'; public function list_provinces() { $this->set('names', $this->Country->find('list')); } public function get_provinces_ajax() { Configure::write('debug', 0); if ($this->RequestHandler->isAjax()) { $this->set('provinces', $this->Country->Province- >find('list', array('conditions' => array('Province.country_id' => $this- >params['url']['countryId']), 'recursive' => -1))); } } function index() {------------ ............................... ............................. // app/views/countries/get_provinces_ajax.ctp <?php if(isset($provinces)) { echo $this->Js->object($provinces); } ?> No me sale el segundo select provinces. He seguido el siguiente ejemplo, http://nuts-and-bolts-of-cakephp.com/2010/03/10/use-cakephp-jquery-to-build-dynamic-selects/#comment-11431 Gracia a todos -- Has recibido este mensaje porque estás suscrito al grupo "CakePHP-es" de Grupos de Google. Para publicar una entrada en este grupo, envía un correo electrónico a cakephp-es@googlegroups.com. Para anular tu suscripción a este grupo, envía un correo electrónico a cakephp-es+unsubscr...@googlegroups.com Para tener acceso a más opciones, visita el grupo en http://groups.google.com/group/cakephp-es?hl=es.