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:
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:
- <?php
- /**
- * clienteForm Form
- * @author <your name here>
- */
- class clienteForm extends TPage
- {
- private $form; // form
- private $telefones;
- /**
- * Form constructor
- * @param $param Request
- */
- public function __construct( $param )
- {
- parent::__construct();
-
- // creates the form
- $this->form = new BootstrapFormBuilder('form_clientes');
- $this->form->setFormTitle('Cadastro de Clientes');
- $this->form->appendPage('Dados Básicos');
-
- // create the form fields
- $id = new TEntry('id');
- $NOME = new TEntry('NOME');
- $CPF = new TEntry('CPF');
- $RG = new TEntry('RG');
- $NASCIMENTO = new TDate('NASCIMENTO');
- $PAI = new TEntry('PAI');
- $MAE = new TEntry('MAE');
- $FOTO = new TFile('FOTO');
- $DATACADASTRO = new TDate('DATACADASTRO');
- $TRABALHO = new TEntry('TRABALHO');
- $ADMISSAO = new TDate('ADMISSAO');
- $RENDA = new TEntry('RENDA');
- $CASA = new TEntry('CASA');
- $DEPENDENTES = new TEntry('DEPENDENTES');
- $PROFISSAO = new TEntry('PROFISSAO');
- $DESDE = new TDate('DESDE');
- $LIMITE = new TEntry('LIMITE');
- $ENDTRABALHO = new TEntry('ENDTRABALHO');
- $ATIVO = new TRadioGroup('ATIVO');
- $items = [ '1' => 'Sim', '2' => 'Não' ];
- $ATIVO->addItems($items);
- $ATIVO->setLayout('horizontal');
- $ATIVO->setUseButton();
- $ATIVO->setValue('1');
- $ADICIONAL = new TEntry('ADICIONAL');
- $OBSERVACOES = new TText('OBSERVACOES');
- $LIMITEHISTORICO = new TEntry('LIMITEHISTORICO');
- $REFERENCIACOMERCIAL = new TEntry('REFERENCIACOMERCIAL');
- $REFERENCIAPESSOAL = new TEntry('REFERENCIAPESSOAL');
- $COMPROVANTERENDA = new TEntry('COMPROVANTERENDA');
- $COMPROVANTEENDERECO = new TEntry('COMPROVANTEENDERECO');
-
-
- $FOTO->setAllowedExtensions( ['gif', 'png', 'jpg', 'jpeg'] );
- $FOTO->enableFileHandling();
- // add the fields
- $this->form->addFields( [ new TLabel('ID') ], [ $id ], [ new TLabel('Ativo') ], [ $ATIVO ] );
- $this->form->addFields([ new TLabel('Nome') ], [ $NOME ] );
- $this->form->addFields( [ new TLabel('CPF') ], [ $CPF ] );
- $this->form->addFields( [ new TLabel('Rg') ], [ $RG ] );
- $this->form->addFields( [ new TLabel('Nascimento') ], [ $NASCIMENTO ] );
- $this->form->addFields( [ new TLabel('Pai') ], [ $PAI ] );
- $this->form->addFields( [ new TLabel('Mae') ], [ $MAE ] );
- $this->form->addFields( [ new TLabel('Foto') ], [ $FOTO ] );
-
- $NOME->addValidation('Nome', new TRequiredValidator);
- $CPF->addValidation('Cpf', new TRequiredValidator);
-
- //#############################################################################################
- $this->form->appendPage('Telefones Cliente');
-
- $dddaux = new TEntry('DDD[]');
- $dddaux->setSize('100%');
-
- $telefoneaux = new TEntry('TELEFONE[]');
- $telefoneaux->setSize('100%');
-
- $this->telefones = new TFieldList;
- $this->form->addField($dddaux);
- $this->form->addField($telefoneaux);
-
- $this->telefones->addField( '<b>DDD</b>', $dddaux, ['width' => '50%']);
- $this->telefones->addField( '<b>Telefone</b>', $telefoneaux, ['width' => '50%']);
-
- $this->telefones->enableSorting();
-
- $this->form->addContent( [ new TLabel('Telefones') ], [ $this->telefones ] );
-
-
-
- //#############################################################################################
-
-
-
-
- $this->form->appendPage('Endereços');
- $this->form->appendPage('Histórico do Cliente');
- $this->form->appendPage('Outras Informações');
- $this->form->addFields( [ new TLabel('Datacadastro') ], [ $DATACADASTRO ] );
- $this->form->addFields( [ new TLabel('Trabalho') ], [ $TRABALHO ] );
- $this->form->addFields( [ new TLabel('Admissao') ], [ $ADMISSAO ] );
- $this->form->addFields( [ new TLabel('Renda') ], [ $RENDA ] );
- $this->form->addFields( [ new TLabel('Casa') ], [ $CASA ] );
- $this->form->addFields( [ new TLabel('Dependentes') ], [ $DEPENDENTES ] );
- $this->form->addFields( [ new TLabel('Profissao') ], [ $PROFISSAO ] );
- $this->form->addFields( [ new TLabel('Desde') ], [ $DESDE ] );
- $this->form->addFields( [ new TLabel('Limite') ], [ $LIMITE ] );
- $this->form->addFields( [ new TLabel('End. trabalho') ], [ $ENDTRABALHO ] );
- $this->form->addFields( [ new TLabel('Adicional') ], [ $ADICIONAL ] );
- $this->form->addFields( [ new TLabel('Observacoes') ], [ $OBSERVACOES ] );
- $this->form->addFields( [ new TLabel('Limitehistorico') ], [ $LIMITEHISTORICO ] );
- $this->form->addFields( [ new TLabel('Referenciacomercial') ], [ $REFERENCIACOMERCIAL ] );
- $this->form->addFields( [ new TLabel('Referenciapessoal') ], [ $REFERENCIAPESSOAL ] );
- $this->form->addFields( [ new TLabel('Comprovanterenda') ], [ $COMPROVANTERENDA ] );
- $this->form->addFields( [ new TLabel('Comprovanteendereco') ], [ $COMPROVANTEENDERECO ] );
- // set sizes
- $id->setSize('35%');
- $NOME->setSize('100%');
- $NOME->forceUpperCase();
- $CPF->setSize('40%');
- $CPF->setMask('999.999.999-99');
- $RG->setSize('40%');
- $NASCIMENTO->setSize('40%');
- $NASCIMENTO->setMask('dd/mm/yyyy');
- $PAI->setSize('100%');
- $PAI->forceUpperCase();
- $MAE->setSize('100%');
- $MAE->forceUpperCase();
- $FOTO->setSize('100%');
- $ATIVO->setSize('100%');
-
- $DATACADASTRO->setSize('100%');
- $TRABALHO->setSize('100%');
- $ADMISSAO->setSize('100%');
- $RENDA->setSize('100%');
- $CASA->setSize('100%');
- $DEPENDENTES->setSize('100%');
- $PROFISSAO->setSize('100%');
- $DESDE->setSize('100%');
- $LIMITE->setSize('100%');
- $ENDTRABALHO->setSize('100%');
-
- $ADICIONAL->setSize('100%');
- $OBSERVACOES->setSize('100%');
- $LIMITEHISTORICO->setSize('100%');
- $REFERENCIACOMERCIAL->setSize('100%');
- $REFERENCIAPESSOAL->setSize('100%');
- $COMPROVANTERENDA->setSize('100%');
- $COMPROVANTEENDERECO->setSize('100%');
- if (!empty($id))
- {
- $id->setEditable(FALSE);
- }
-
- /** samples
- $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
- $fieldX->setSize( '100%' ); // set size
- **/
-
- // create the form actions
- $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:floppy-o');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addAction(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
-
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 90%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
-
- parent::add($container);
- }
- /**
- * Save form data
- * @param $param Request
- */
- public function onSave( $param )
- {
- try
- {
- TTransaction::open('sample'); // open a transaction
-
- /**
- // Enable Debug logger for SQL operations inside the transaction
- TTransaction::setLogger(new TLoggerSTD); // standard output
- TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
- **/
-
- $this->form->validate(); // validate form data
- $data = $this->form->getData(); // get form data as array
-
- $object = new cliente; // create an empty object
- $object->fromArray( (array) $data); // load the object with data
- $object->store(); // save the object
-
- // get the generated id
- $data->id = $object->id;
-
- $this->form->setData($data); // fill form data
- TTransaction::close(); // close the transaction
-
- new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- $this->form->setData( $this->form->getData() ); // keep form data
- TTransaction::rollback(); // undo all pending operations
- }
- }
-
- /**
- * Clear form data
- * @param $param Request
- */
- public function onClear( $param )
- {
- $this->form->clear(TRUE);
- }
-
- /**
- * Load object to form data
- * @param $param Request
- */
- public function onEdit( $param )
- {
- try
- {
- if (isset($param['key']))
- {
- $key = $param['key']; // get the parameter $key
- TTransaction::open('sample'); // open a transaction
- $object = new cliente($key); // instantiates the Active Record
- $this->form->setData($object); // fill the form
- TTransaction::close(); // close the transaction
- }
- else
- {
- $this->form->clear(TRUE);
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- }
- ?>
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.
Perfeito Nataniel!
Mais uma dúvida... você sabe me dizer se tem no tutor algum exemplo de utilização do TMultifield?