TFieldList não é adiciona ao formulário Olá, a todos, Estou tendo um problema ao tentar adicionar o componente TFieldList ao formulário, porém não estou tendo sucesso. Aguém consegue me auxliar. Segue código fonte abaixo e imagem com a descrição do erro. ...
RB
TFieldList não é adiciona ao formulário  
Olá, a todos,

Estou tendo um problema ao tentar adicionar o componente TFieldList ao formulário, porém não estou tendo sucesso.

Aguém consegue me auxliar.

Segue código fonte abaixo e imagem com a descrição do erro.


 
  1. <?php
  2. class ClienteFisico extends TPage
  3. {
  4. private $form;
  5. private $db = 'teste';
  6. private $contato_list;
  7. private $telefone_list;
  8. private $contacts;
  9. private $telefones;
  10. /**
  11. * Class constructor
  12. * Creates the page
  13. */
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. parent::include_css('app/resources/form.css');
  18. $this->form = new BootstrapFormBuilder('form_fisico');
  19. $this->form->setFormTitle('');
  20. $this->form->setFieldSizes('100%');
  21. $this->form->style = 'border 1px solid #546';
  22. $this->form->generateAria(); // automatic aria-label
  23. $this->form->appendPage('Dados Pessoais');
  24. $id = new TEntry('id');
  25. $nome = new TEntry('nome');
  26. $cpf = new TEntry('cpf');
  27. $rg = new TEntry('rg');
  28. $uf_rg = new TEntry('uf_rg');
  29. $data_emissao_rg = new TDate('data_emissao_rg');
  30. $data_nascimento = new TDate('data_nascimento');
  31. $genero_id = new TCombo('genero_id');
  32. $estado_civil_id = new TDBUniqueSearch('estado_civil_id', $this->db, 'EstadoCivil', 'id', 'nome');
  33. $homephone = new TEntry('homephone');
  34. $naturalidade = new TEntry('naturalidade');
  35. $street = new TEntry('logradouro');
  36. $number = new TEntry('numero');
  37. $complemento = new TEntry('complemento');
  38. $neighborhood = new TEntry('bairro');
  39. $localidade = new TEntry('localidade');
  40. $municipio = new TEntry('municipio');
  41. $state = new TEntry('uf');
  42. $cep = new TEntry('cep');
  43. $id->setEditable(false);
  44. $genero_id->addItems(['1' => 'Masculino', '2' => 'Feminino']);
  45. //formata mascaras
  46. $cpf->setMask('999.999.999-99');
  47. $cep->setMask('99.999-999', true);
  48. $data_nascimento->setMask('dd/mm/yyyy');
  49. $data_emissao_rg->setMask('dd/mm/yyyy');
  50. $homephone->setMask('(99)9999-99999');
  51. $data_nascimento->setDatabaseMask('yyyy-mm-dd');
  52. $data_emissao_rg->setDatabaseMask('yyyy-mm-dd');
  53. $row = $this->form->addFields( [ new TLabel('Código'),$id ],
  54. [ new TLabel('Nome'),$nome ],
  55. [ new TLabel('Data de Nascimento'),$data_nascimento ],
  56. [ new TLabel('Genero'),$genero_id],
  57. [ new TLabel('Estado Cívil'),$estado_civil_id]
  58. );
  59. $row->layout = ['col-sm-1','col-sm-5','col-sm-2','col-sm-2','col-sm-2'];
  60. $row = $this->form->addFields( [ new TLabel('RG'),$rg ],
  61. [ new TLabel(_t('State')),$uf_rg],
  62. [ new TLabel('Data de Emissão'),$data_emissao_rg ],
  63. [ new TLabel('CPF'),$cpf],
  64. [ new TLabel('Título Eleitor'),$homephone ],
  65. [ new TLabel('Naturalidade'),$naturalidade ]);
  66. $row->layout = ['col-sm-2', 'col-sm-1', 'col-sm-2', 'col-sm-2', 'col-sm-2', 'col-sm-2'];
  67. $label2 = new TLabel(_t('Address'), '#5A73DB', 12, '');
  68. $label2->style='text-align:left;border-bottom:1px solid #c0c0c0;width:100%';
  69. $this->form->addContent( [$label2] );
  70. $row = $this->form->addFields(
  71. [ new TLabel('Cep'),$cep ] ,
  72. [ new TLabel(_t('Street')),$street ],
  73. [ new TLabel(_t('Number')),$number ],
  74. [ new TLabel(_t('complement')),$complemento ]
  75. );
  76. $row->layout = ['col-sm-2', 'col-sm-5', 'col-sm-2','col-sm-3'];
  77. $row = $this->form->addFields( [ new TLabel(_t('Neighborhood')),$neighborhood ],
  78. [ new TLabel(_t('County')),$municipio ],
  79. [ new TLabel(_t('City')),$localidade ],
  80. [ new TLabel(_t('State')),$state ]
  81. );
  82. $row->layout = ['col-sm-4','col-sm-4', 'col-sm-3','col-sm-1'];
  83. $this->form->appendPage('Contatos');
  84. /*
  85. //Cria campos dos telefones
  86. $ddi = new TEntry('ddi[]');
  87. $ddi->setMask('99');
  88. $ddi->setSize('100%');
  89. $ddi->style = 'text-align: right';
  90. $ddd = new TEntry('ddd[]');
  91. $ddd->setMask('999');
  92. $ddd->setSize('100%');
  93. $ddd->style = 'text-align: right';
  94. // create detail fields
  95. $tipo_telefone_id = new TDBUniqueSearch('tipo_telefone_id[]', '$db', 'TipoTelefone', 'id', 'nome');
  96. $tipo_telefone_id->setMinLength(1);
  97. $tipo_telefone_id->setSize('100%');
  98. $tipo_telefone_id->setMask('{nome} ({id})');
  99. $numero_telefone = new TEntry('numero_telefone[]');
  100. $numero_telefone->setMask('9999-9999');
  101. $numero_telefone->setSize('100%');
  102. $numero_telefone->style = 'text-align: right';
  103. //$numero_telefone->setChangeAction(new TAction(array($this, 'onChangeProduct')));
  104. $this->form->addField($ddi);
  105. $this->form->addField($ddd);
  106. $this->form->addField($tipo_telefone_id);
  107. $this->form->addField($numero_telefone);
  108. // detail
  109. $this->telefone_list = new TFieldList;
  110. $this->telefone_list->generateAria();
  111. $this->telefone_list->addField( '<b>DDI</b>',$ddi ,['width' => '50px']);
  112. $this->telefone_list->addField( '<b>DDD</b>',$ddd , ['width' => '50px']);
  113. $this->telefone_list->addField( '<b>Tipo</b>',$tipo_telefone_id, ['width' => '42%']);
  114. $this->telefone_list->addField( '<b>Número</b>',$numero_telefone,['width' => '42%']);
  115. $this->telefone_list-> width = '100%';
  116. $this->telefone_list->enableSorting();
  117. // add field list to the form
  118. //$this->form->addContent( [$this->telefone_list] );
  119. $row = $this->form->addFields([$this->telefone_list]);
  120. $row->layout = ['col-sm-12' ];
  121. */
  122. //cria campos dos contatos
  123. $nome_contato = new TEntry('nome_contato[]');
  124. $nome_contato->setSize('100%');
  125. $nome_contato->style = 'text-align: right';
  126. // create detail fields
  127. $tipo_contato_id = new TDBUniqueSearch('tipo_contato_id[]', '$db', 'TipoContato', 'id', 'nome');
  128. $tipo_contato_id->setMinLength(1);
  129. $tipo_contato_id->setSize('100%');
  130. $tipo_contato_id->setMask('{nome} ({id})');
  131. //$parentesco_id = new TEntry('parentesco_id[]');
  132. //$parentesco_id->setSize('100%');
  133. //$parentesco_id->style = 'text-align: right';
  134. $this->form->addField($nome_contato);
  135. $this->form->addField($tipo_contato_id);
  136. //$this->form->addField($parentesco_id);
  137. // detail
  138. $this->contato_list = new TFieldList;
  139. $this->contato_list->addField( '<b>DDI</b>',$nome_contato ,['width' => '50px']);
  140. $this->contato_list->addField( '<b>DDD</b>',$tipo_contato_id , ['width' => '50px']);
  141. //$this->contato_list->addField( '<b>Grau Parentesco</b>',$parentesco_id, ['width' => '42%']);
  142. $this->contato_list-> width = '100%';
  143. $this->contato_list->enableSorting();
  144. //$this->form->addContent( [ new TLabel('Contatos') ], [ $this->contacts ] );
  145. $row = $this->form->addFields([$this->contato_list]);
  146. $row->layout = ['col-sm-12' ];
  147. $row = $this->form->addFields( [ new TLabel('Pai'), $t1 = new TEntry('pai') ],
  148. [ new TLabel('Mãe'), $t2 = new TEntry('mae') ] );
  149. $row->layout = ['col-sm-4', 'col-sm-8' ];
  150. $row = $this->form->addFields( [ new TLabel('Test3'), $text = new TText('text') ] );
  151. $row->layout = ['col-sm-12' ];
  152. $cpf->addValidation('CPF', new TRequiredValidator);
  153. $data_nascimento->addValidation('Data de Nascimento', new TRequiredValidator);
  154. $genero_id->addValidation('Genero', new TRequiredValidator);
  155. $estado_civil_id->addValidation('Estado Cívil', new TRequiredValidator);
  156. $cep->addValidation('CEP', new TRequiredValidator);
  157. $this->form->addAction(_t('Send'), new TAction(array($this, 'onSend')), 'far:check-circle green');
  158. // wrap the page content using vertical box
  159. $vbox = new TVBox;
  160. $vbox->style = 'width: 100%';
  161. $vbox->add(new TXMLBreadCrumb('menu.xml', 'DataGridClienteFisico'));
  162. $vbox->add($this->form);
  163. parent::add($vbox);
  164. }
  165. /**
  166. * Post data
  167. */
  168. public function onSend($param)
  169. {
  170. try
  171. {
  172. // open a transaction with database 'samples'
  173. TTransaction::open($this->db);
  174. $this->form->validate(); // run form validation
  175. $data = $this->form->getData(); // get form data as array
  176. $pessoa = new Pessoa; // create an empty object
  177. $pessoa->fromArray( (array) $data); // load the object with data
  178. $pessoa->tipo_pessoa_id = 1;
  179. $pessoa->situacao_id = 1;
  180. $pessoa->store(); // save the object
  181. if($pessoa)
  182. {
  183. if( !empty($param['tipo_contato_id']) AND is_array($param['tipo_contato_id']) )
  184. {
  185. foreach( $param['tipo_contato_id'] as $row => $tipo_contato_id)
  186. {
  187. if ($tipo_contato_id)
  188. {
  189. $contato = new Contato;
  190. $contato->pessoa_id = $pessoa->id;
  191. $contato->system_unit_id = TSession::getValue('userunitids');
  192. $contato->tipo_contato_id = $param['tipo_contato_id'][$row];
  193. $contato->nome = $param['nome_contato'][$row];
  194. $contato->atualizacao = date('Y-m-d H:m:s:s');
  195. // add the contact to the customer
  196. $pessoa->addContact($contato);
  197. }
  198. }
  199. }
  200. $cpf = preg_replace("/[^0-9]/", "", $data->cpf);
  201. //echo $cpf;
  202. $fisica = new Fisica;
  203. $fisica->pessoa_id = $pessoa->id;
  204. $fisica->nome = $data->nome;
  205. $fisica->data_nascimento = $data->data_nascimento;
  206. $fisica->genero_id = $data->genero_id;
  207. $fisica->estado_civil_id = $data->estado_civil_id;
  208. $fisica->cpf = preg_replace("/[^0-9]/", "", $data->cpf);
  209. $fisica->rg = preg_replace("/[^0-9]/", "", $data->rg);
  210. $fisica->uf_rg = $data->uf_rg;
  211. $fisica->data_emissao_rg = $data->data_emissao_rg;
  212. $fisica->orgao_expedidor_rg = $data->uf_rg;
  213. $fisica->titulo_eleitor = $data->homephone;
  214. $fisica->uf_titulo_eleitor = $data->uf_rg;
  215. $fisica->naturalidade = $data->naturalidade;
  216. $fisica->pai = $data->pai;
  217. $fisica->mae = $data->mae;
  218. $fisica->store();
  219. }
  220. // fill the form with the active record data
  221. $data->id = $pessoa->id;
  222. $this->form->setData($data);
  223. TTransaction::close(); // close the transaction
  224. // shows the success message
  225. new TMessage('info', 'Record saved');
  226. }
  227. catch (Exception $e) // in case of exception
  228. {
  229. new TMessage('error', $e->getMessage()); // shows the exception error message
  230. $this->form->setData( $this->form->getData() ); // keep form data
  231. TTransaction::rollback(); // undo all pending operations
  232. }
  233. }
  234. /**
  235. * Executed whenever the user clicks at the edit button da datagrid
  236. */
  237. public function onEdit($param)
  238. {
  239. try
  240. {
  241. if (isset($param['pessoa_id']))
  242. {
  243. TTransaction::open($this->db);
  244. $key = $param['pessoa_id'];
  245. $object = Fisica::find($key);
  246. $object->id = $object->pessoa_id;
  247. $object->id = $object->pessoa_id;
  248. $this->form->setData($object); // fill the form with the active record data
  249. // load the contacts (composition)
  250. $contacts = $object->pessoa->pessoa_vinculo->getcontatos();
  251. print_r($contacts);
  252. if ($contacts)
  253. {
  254. $this->contacts->addHeader();
  255. foreach ($contacts as $contact)
  256. {
  257. $contact_detail = new stdClass;
  258. $contact_detail->tipo_contato_id = $contact->tipo_contato_id;
  259. $contact_detail->nome_contato = $contact->nome;
  260. $this->contacts->addDetail($contact_detail);
  261. }
  262. $this->contacts->addCloneAction();
  263. }
  264. else
  265. {
  266. $this->onClear($param);
  267. }
  268. }
  269. TTransaction::close(); // close transaction
  270. }
  271. catch (Exception $e) // in case of exception
  272. {
  273. new TMessage('error', $e->getMessage());
  274. TTransaction::rollback();
  275. }
  276. }
  277. /**
  278. * Clear form
  279. */
  280. public function onClear($param)
  281. {
  282. $this->form->clear();
  283. $this->contacts->addHeader();
  284. $this->contacts->addDetail( new stdClass );
  285. $this->contacts->addCloneAction();
  286. }
  287. }

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (2)


FC

Parece que faltou a linha de inclusão no form:

 
  1. <?php
  2. $this->form->addContent( [$this->fieldlist] );
  3. ?>
RB

Felipe Cortez: Resolvido.

Muito obrigado pela dica, funcionou perfeito.

Nada como um olhar externo.

Valeu.