TFieldList não aparece no formulário Bom dia a todos do Fórum! Pessoal, criei um TFieldList no meu formulário mas ele não está aparecendo. Na verdade só está aparecendo a legenda dele (no caso Telefones), mas os campos não. Será que estou esquecendo de alguma coisa? Obrigado a todos pela ajuda! Segue o código utilizado: ...
AN
TFieldList não aparece no formulário  
Bom dia a todos do Fórum!
Pessoal, criei um TFieldList no meu formulário mas ele não está aparecendo. Na verdade só está aparecendo a legenda dele (no caso Telefones), mas os campos não.
Será que estou esquecendo de alguma coisa?

Obrigado a todos pela ajuda!

Segue o código utilizado:

 
  1. <?php
  2. /**
  3. * clienteForm Form
  4. * @author <your name here>
  5. */
  6. class clienteForm extends TPage
  7. {
  8. private $form; // form
  9. private $telefones;
  10. /**
  11. * Form constructor
  12. * @param $param Request
  13. */
  14. public function __construct( $param )
  15. {
  16. parent::__construct();
  17. // creates the form
  18. $this->form = new BootstrapFormBuilder('form_clientes');
  19. $this->form->setFormTitle('Cadastro de Clientes');
  20. $this->form->appendPage('Dados Básicos');
  21. // create the form fields
  22. $id = new TEntry('id');
  23. $NOME = new TEntry('NOME');
  24. $CPF = new TEntry('CPF');
  25. $RG = new TEntry('RG');
  26. $NASCIMENTO = new TDate('NASCIMENTO');
  27. $PAI = new TEntry('PAI');
  28. $MAE = new TEntry('MAE');
  29. $FOTO = new TFile('FOTO');
  30. $DATACADASTRO = new TDate('DATACADASTRO');
  31. $TRABALHO = new TEntry('TRABALHO');
  32. $ADMISSAO = new TDate('ADMISSAO');
  33. $RENDA = new TEntry('RENDA');
  34. $CASA = new TEntry('CASA');
  35. $DEPENDENTES = new TEntry('DEPENDENTES');
  36. $PROFISSAO = new TEntry('PROFISSAO');
  37. $DESDE = new TDate('DESDE');
  38. $LIMITE = new TEntry('LIMITE');
  39. $ENDTRABALHO = new TEntry('ENDTRABALHO');
  40. $ATIVO = new TRadioGroup('ATIVO');
  41. $items = [ '1' => 'Sim', '2' => 'Não' ];
  42. $ATIVO->addItems($items);
  43. $ATIVO->setLayout('horizontal');
  44. $ATIVO->setUseButton();
  45. $ATIVO->setValue('1');
  46. $ADICIONAL = new TEntry('ADICIONAL');
  47. $OBSERVACOES = new TText('OBSERVACOES');
  48. $LIMITEHISTORICO = new TEntry('LIMITEHISTORICO');
  49. $REFERENCIACOMERCIAL = new TEntry('REFERENCIACOMERCIAL');
  50. $REFERENCIAPESSOAL = new TEntry('REFERENCIAPESSOAL');
  51. $COMPROVANTERENDA = new TEntry('COMPROVANTERENDA');
  52. $COMPROVANTEENDERECO = new TEntry('COMPROVANTEENDERECO');
  53. $FOTO->setAllowedExtensions( ['gif', 'png', 'jpg', 'jpeg'] );
  54. $FOTO->enableFileHandling();
  55. // add the fields
  56. $this->form->addFields( [ new TLabel('ID') ], [ $id ], [ new TLabel('Ativo') ], [ $ATIVO ] );
  57. $this->form->addFields([ new TLabel('Nome') ], [ $NOME ] );
  58. $this->form->addFields( [ new TLabel('CPF') ], [ $CPF ] );
  59. $this->form->addFields( [ new TLabel('Rg') ], [ $RG ] );
  60. $this->form->addFields( [ new TLabel('Nascimento') ], [ $NASCIMENTO ] );
  61. $this->form->addFields( [ new TLabel('Pai') ], [ $PAI ] );
  62. $this->form->addFields( [ new TLabel('Mae') ], [ $MAE ] );
  63. $this->form->addFields( [ new TLabel('Foto') ], [ $FOTO ] );
  64. $NOME->addValidation('Nome', new TRequiredValidator);
  65. $CPF->addValidation('Cpf', new TRequiredValidator);
  66. //#############################################################################################
  67. $this->form->appendPage('Telefones Cliente');
  68. $dddaux = new TEntry('DDD[]');
  69. $dddaux->setSize('100%');
  70. $telefoneaux = new TEntry('TELEFONE[]');
  71. $telefoneaux->setSize('100%');
  72. $this->telefones = new TFieldList;
  73. $this->form->addField($dddaux);
  74. $this->form->addField($telefoneaux);
  75. $this->telefones->addField( '<b>DDD</b>', $dddaux, ['width' => '50%']);
  76. $this->telefones->addField( '<b>Telefone</b>', $telefoneaux, ['width' => '50%']);
  77. $this->telefones->enableSorting();
  78. $this->form->addContent( [ new TLabel('Telefones') ], [ $this->telefones ] );
  79. //#############################################################################################
  80. $this->form->appendPage('Endereços');
  81. $this->form->appendPage('Histórico do Cliente');
  82. $this->form->appendPage('Outras Informações');
  83. $this->form->addFields( [ new TLabel('Datacadastro') ], [ $DATACADASTRO ] );
  84. $this->form->addFields( [ new TLabel('Trabalho') ], [ $TRABALHO ] );
  85. $this->form->addFields( [ new TLabel('Admissao') ], [ $ADMISSAO ] );
  86. $this->form->addFields( [ new TLabel('Renda') ], [ $RENDA ] );
  87. $this->form->addFields( [ new TLabel('Casa') ], [ $CASA ] );
  88. $this->form->addFields( [ new TLabel('Dependentes') ], [ $DEPENDENTES ] );
  89. $this->form->addFields( [ new TLabel('Profissao') ], [ $PROFISSAO ] );
  90. $this->form->addFields( [ new TLabel('Desde') ], [ $DESDE ] );
  91. $this->form->addFields( [ new TLabel('Limite') ], [ $LIMITE ] );
  92. $this->form->addFields( [ new TLabel('End. trabalho') ], [ $ENDTRABALHO ] );
  93. $this->form->addFields( [ new TLabel('Adicional') ], [ $ADICIONAL ] );
  94. $this->form->addFields( [ new TLabel('Observacoes') ], [ $OBSERVACOES ] );
  95. $this->form->addFields( [ new TLabel('Limitehistorico') ], [ $LIMITEHISTORICO ] );
  96. $this->form->addFields( [ new TLabel('Referenciacomercial') ], [ $REFERENCIACOMERCIAL ] );
  97. $this->form->addFields( [ new TLabel('Referenciapessoal') ], [ $REFERENCIAPESSOAL ] );
  98. $this->form->addFields( [ new TLabel('Comprovanterenda') ], [ $COMPROVANTERENDA ] );
  99. $this->form->addFields( [ new TLabel('Comprovanteendereco') ], [ $COMPROVANTEENDERECO ] );
  100. // set sizes
  101. $id->setSize('35%');
  102. $NOME->setSize('100%');
  103. $NOME->forceUpperCase();
  104. $CPF->setSize('40%');
  105. $CPF->setMask('999.999.999-99');
  106. $RG->setSize('40%');
  107. $NASCIMENTO->setSize('40%');
  108. $NASCIMENTO->setMask('dd/mm/yyyy');
  109. $PAI->setSize('100%');
  110. $PAI->forceUpperCase();
  111. $MAE->setSize('100%');
  112. $MAE->forceUpperCase();
  113. $FOTO->setSize('100%');
  114. $ATIVO->setSize('100%');
  115. $DATACADASTRO->setSize('100%');
  116. $TRABALHO->setSize('100%');
  117. $ADMISSAO->setSize('100%');
  118. $RENDA->setSize('100%');
  119. $CASA->setSize('100%');
  120. $DEPENDENTES->setSize('100%');
  121. $PROFISSAO->setSize('100%');
  122. $DESDE->setSize('100%');
  123. $LIMITE->setSize('100%');
  124. $ENDTRABALHO->setSize('100%');
  125. $ADICIONAL->setSize('100%');
  126. $OBSERVACOES->setSize('100%');
  127. $LIMITEHISTORICO->setSize('100%');
  128. $REFERENCIACOMERCIAL->setSize('100%');
  129. $REFERENCIAPESSOAL->setSize('100%');
  130. $COMPROVANTERENDA->setSize('100%');
  131. $COMPROVANTEENDERECO->setSize('100%');
  132. if (!empty($id))
  133. {
  134. $id->setEditable(FALSE);
  135. }
  136. /** samples
  137. $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  138. $fieldX->setSize( '100%' ); // set size
  139. **/
  140. // create the form actions
  141. $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:floppy-o');
  142. $btn->class = 'btn btn-sm btn-primary';
  143. $this->form->addAction(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
  144. // vertical box container
  145. $container = new TVBox;
  146. $container->style = 'width: 90%';
  147. // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  148. $container->add($this->form);
  149. parent::add($container);
  150. }
  151. /**
  152. * Save form data
  153. * @param $param Request
  154. */
  155. public function onSave( $param )
  156. {
  157. try
  158. {
  159. TTransaction::open('sample'); // open a transaction
  160. /**
  161. // Enable Debug logger for SQL operations inside the transaction
  162. TTransaction::setLogger(new TLoggerSTD); // standard output
  163. TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  164. **/
  165. $this->form->validate(); // validate form data
  166. $data = $this->form->getData(); // get form data as array
  167. $object = new cliente; // create an empty object
  168. $object->fromArray( (array) $data); // load the object with data
  169. $object->store(); // save the object
  170. // get the generated id
  171. $data->id = $object->id;
  172. $this->form->setData($data); // fill form data
  173. TTransaction::close(); // close the transaction
  174. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  175. }
  176. catch (Exception $e) // in case of exception
  177. {
  178. new TMessage('error', $e->getMessage()); // shows the exception error message
  179. $this->form->setData( $this->form->getData() ); // keep form data
  180. TTransaction::rollback(); // undo all pending operations
  181. }
  182. }
  183. /**
  184. * Clear form data
  185. * @param $param Request
  186. */
  187. public function onClear( $param )
  188. {
  189. $this->form->clear(TRUE);
  190. }
  191. /**
  192. * Load object to form data
  193. * @param $param Request
  194. */
  195. public function onEdit( $param )
  196. {
  197. try
  198. {
  199. if (isset($param['key']))
  200. {
  201. $key = $param['key']; // get the parameter $key
  202. TTransaction::open('sample'); // open a transaction
  203. $object = new cliente($key); // instantiates the Active Record
  204. $this->form->setData($object); // fill the form
  205. TTransaction::close(); // close the transaction
  206. }
  207. else
  208. {
  209. $this->form->clear(TRUE);
  210. }
  211. }
  212. catch (Exception $e) // in case of exception
  213. {
  214. new TMessage('error', $e->getMessage()); // shows the exception error message
  215. TTransaction::rollback(); // undo all pending operations
  216. }
  217. }
  218. }
  219. ?>

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)


NR

Veja a função onClear do exemplo abaixo:
adianti.com.br/framework_files/tutor/index.php?class=SaleMultiValueF

Você precisa chamar a função addDetail.
AN

Perfeito Nataniel!
Mais uma dúvida... você sabe me dizer se tem no tutor algum exemplo de utilização do TMultifield?