JH
TFilelList só carrega a primeira linha.
Boa tarde Pessoal estou tentando carregar o TFieldList no método onEdit, porém só carrega a primeira linha segue o código abaixo. Agradeço desde já:
- <?php
- class OrdemPagamentoCadastroForm extends TPage
- {
- private $form;
- /**
- * Class constructor
- * Creates the page
- */
- public function __construct()
- {
- parent::__construct();
- $this->form = new BootstrapFormBuilder('form_cadastro_etapa');
- $this->form->setFormTitle('Cadastro Etapa');
- $this->form->setFieldSizes('100%');
- //$this->form->generateAria(); // automatic aria-label
- $id = new THidden('id');
- $nome = new TEntry('nome');
- $combo_fk_id_formulario = new TCombo('fk_id_formulario');
- $combo_fk_id_formulario->enableSearch();
- $combo_fk_id_formulario->addItems(['1'=>'Ordem de Pagamento São Paulo','2'=>'Ordem de Pagamento Salvador']);
- $combo_fk_id_formulario->setSize('100%');
- $this->form->addFields( [$id]);
- $this->form->addFields([new TLabel('Nome:')], [$nome]);
- $this->form->addFields([new TLabel('Formulario:')], [$combo_fk_id_formulario]);
- $fk_id_usuario = new TDBCombo('fk_id_usuario[]', TSession::getValue('arquivo_banco'), 'SystemUser', 'id', 'name', 'name asc');
- $fk_id_usuario->enableSearch();
- $fk_id_usuario->setSize('100%');
- $this->fieldlist = new TFieldList;
- $this->fieldlist->width = '100%';
- $this->fieldlist->class .= ' dashed'; // important
- $this->fieldlist->name = 'field_list_usuarios';
- $this->fieldlist->addField( '<b>Usuario - Ordem </b>', $fk_id_usuario, ['width' => '25%'] );
- $this->fieldlist->enableSorting();
- $this->form->addField($fk_id_usuario);
- $this->fieldlist->addHeader();
- $this->fieldlist->addDetail( new stdClass );
- $this->fieldlist->addCloneAction();
- // add field list to the form
- $this->form->addContent([], [$this->fieldlist]);
- $this->form->addAction('Salvar', new TAction(array($this, 'onSave')), 'far:check-circle green');
- // wrap the page content using vertical box
- $vbox = new TVBox;
- $vbox->style = 'width: 100%';
- //$vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $vbox->add($this->form);
- parent::add($vbox);
- }
- /**
- * Post data
- */
- public function onSave($param)
- {
- try
- {
- $data = $this->form->getData();
- TTransaction::open(TSession::getValue('arquivo_banco'));
- TForm::sendData('form_cadastro_etapa', $param);
- $cadastroPagamento = new CadastroEtapa;
- $cadastroPagamento->id = $data->id;
- $cadastroPagamento->nome = $data->nome;
- $cadastroPagamento->fk_id_formulario = $data->fk_id_formulario;
- if(isset($data->fk_id_formulario) || sizeof($data->fk_id_formulario) > 0)
- {
- $cadastroPagamento->store();
- $cont = 0;
- foreach ($data->fk_id_usuario as $user) {
- $etapa_class = new Etapa;
- $etapa_class->fk_id_user = $user;
- $etapa_class->fk_id_formulario = $data->fk_id_formulario;
- $etapa_class->fk_id_cadastro = $cadastroPagamento->id;
- $etapa_class->etapa = $cont;
- $etapa_class->store();
- $cont = $cont + 1;
- }
- }
- TTransaction::close();
- }
- catch (Exception $e)
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- public function onEdit($param)
- {
- $key = $param['key'];
- try
- {
- TTransaction::open(TSession::getValue('arquivo_banco'));
- $cadastroEtapa = new CadastroEtapa($key);
- $criteria = new TCriteria;
- $criteria->add(new TFilter('fk_id_cadastro', '=', $cadastroEtapa->id));
- $etapas = Etapa::getObjects($criteria);
- $stdClass = new stdClass;
- $fk_id_users = [];
- foreach ($etapas as $etapa)
- {
- $fk_id_users[] = $etapa->fk_id_user;
- }
- $qtd_linha = sizeof($fk_id_users) -1 ;
- print_r($fk_id_users);
- $stdClass->id = $cadastroEtapa->id;
- $stdClass->nome = $cadastroEtapa->nome;
- $stdClass->fk_id_formulario = $cadastroEtapa->fk_id_formulario;
- $stdClass->fk_id_usuario = $fk_id_users;
- print_r($stdClass);
- TFieldList::clear('field_list_usuarios');
- TFieldList::addRows('field_list_usuarios', $qtd_linha);
- TForm::sendData('form_cadastro_etapa', $stdClass, false, true, 200); // 200 ms of timeout after recreate rows!
- //$this->form->setData($stdClass);
- TTransaction::close();
- }
- catch (Exception $e)
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- }
- ?>
Tente usar a função addDetail ao invés da TForm::sendData: