データベースから取得した ef_name の値を設定できません。単一の ID に対して複数の行があります。
形
public function addRow()
{
$row_form = new Zend_Form(array(
'elements' => array(
'ef_name' => array(
'type' => 'text'
),
),
));
$new_form_index = count($this->_subForms)+1;
$row_form->setElementsBelongTo('diam['.$new_form_index.']');
$this->addSubform($row_form, $new_form_index);
return $row_form;
}
public function init() {
$this->addElement('hidden', 'id', array(
'value' => 1
));
for($cdr=0;$cdr<10;$cdr++)
$this->addRow();
}
意見
<?php
echo $this->form ;
$this->jQuery()->enable();
?>
<?php $this->jQuery()->onLoadCaptureStart(); ?>
jQuery('#category').change(newEcat);
<?php $this->jQuery()->onLoadCaptureEnd(); ?>
<script><!--
function newEcat()
{
var p = $("#category").val();
var response = $.ajax({
url: "<?php echo $this->url(array('controller'=>'index',
'action'=>'details')) ?>",
type: "GET",
data: {id: p},
cache: false,
success: function(text){
response = text;
$("#category").val($(text).find("select[name='category']").val());
$("#ef_name").val($(text).find("select[name='ef_name']").val());
},
error: function() { alert('Sorry, no family members defined.'); }
});
}
--></script>
コントローラ
if ($this->getRequest()->isXmlHttpRequest()) {
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(TRUE);
$id = $this->_getParam(id);
$form->category->setValue($id);
}